0

I'm trying to horizontally center the actionbar title of an activity under Wear OS 2. The activity class derives from AndroidX.AppCompat.App.AppCompatActivity.

I've tried using styling as shown below but the title stays left-aligned:

<style name="MainTheme" parent="AppBaseTheme">
</style>


<style name="AppBaseTheme" parent="Theme.AppCompat">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="android:actionBarTabTextStyle">@style/MyActionBarTabText</item>
</style>


<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar">
    <item name="android:titleTextStyle">@style/MyActionBar.TitleTextStyle</item>
</style>


<style name="MyActionBar.TitleTextStyle"
    parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textAlignment">center</item>
</style>


<style name="MyActionBarTabText" parent="@style/Widget.AppCompat.ActionBar.TabText">
    <item name="android:textAlignment">center</item>
</style>

I've also tried using a custom SupportActionBar as described here, and various variations on that approach. I suspect that, reasonably enough, Wear OS doesn't support compound action bars and is stripping the enclosing view group from the layout that I give it.

Any suggestions?

Andy Johnson
  • 7,938
  • 4
  • 33
  • 50

0 Answers0