Center text of a Xamarin Forms TabbedPage Title

后端 未结 1 1833
梦毁少年i
梦毁少年i 2021-01-21 02:59

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 nee

相关标签:
1条回答
  • 2021-01-21 03:19

    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/.

    0 讨论(0)
提交回复
热议问题