3

i have a TabbedPage with multiple Child-Pages, with a title each. When the title is short enough to be single line the text gets centered perfectly, but as soon as the text needs more than 1 line it is no longer centered.

Can anyone tell me how to fix this?

enter image description here

StarterPack
  • 498
  • 1
  • 7
  • 28

1 Answers1

3

I think it's impossible to do in common way for all platforms, and you have to do it in platform specific way.

For android project I did it in such way: In file Styles.xml from folder Resources/values I added style

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="CustomTheme" 
        parent="@android:style/Theme.Holo">
        <item name="android:actionBarTabTextStyle">@style/CustomTab</item>
    </style>

    <style name="CustomTab" 
        parent="@android:style/Widget.Holo.ActionBar.TabText">
        <item name="android:gravity">center</item>
    </style>
</resources>

And in MainActivity.cs I added

[Activity(Theme = "@style/CustomTheme")]

For Windows phone I found this article https://nocture.dk/2014/12/10/xamarin-forms-customizing-tabbed-page-header-title-windows-phone/, but didn't try it.

For iOS i didn't check too http://jfarrell.net/2015/02/25/customizing-the-tab-bar-on-ios-with-xamarin-forms/.

Morse
  • 8,258
  • 7
  • 39
  • 64
Yehor Hromadskyi
  • 3,308
  • 1
  • 16
  • 29