Xamarin Forms TabbedPage 标题的中心文本
Center text of a Xamarin Forms TabbedPage Title
我有一个包含多个 Child-Pages 的 TabbedPage,每个都有一个标题。
当标题短到单行时,文本会完美居中,但一旦文本需要超过 1 行,它就不再居中。
谁能告诉我如何解决这个问题?
我认为不可能以通用方式对所有平台进行操作,您必须以特定于平台的方式进行操作。
对于android项目我是这样做的:
在文件夹 Resources/values 的文件 Styles.xml 中,我添加了样式
<?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>
然后在 MainActivity.cs 我添加了
[Activity(Theme = "@style/CustomTheme")]
为了 Windows phone 我找到了这篇文章 https://nocture.dk/2014/12/10/xamarin-forms-customizing-tabbed-page-header-title-windows-phone/,但没有尝试。
对于iOS我也没有检查http://jfarrell.net/2015/02/25/customizing-the-tab-bar-on-ios-with-xamarin-forms/。
我有一个包含多个 Child-Pages 的 TabbedPage,每个都有一个标题。 当标题短到单行时,文本会完美居中,但一旦文本需要超过 1 行,它就不再居中。
谁能告诉我如何解决这个问题?
我认为不可能以通用方式对所有平台进行操作,您必须以特定于平台的方式进行操作。
对于android项目我是这样做的: 在文件夹 Resources/values 的文件 Styles.xml 中,我添加了样式
<?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>
然后在 MainActivity.cs 我添加了
[Activity(Theme = "@style/CustomTheme")]
为了 Windows phone 我找到了这篇文章 https://nocture.dk/2014/12/10/xamarin-forms-customizing-tabbed-page-header-title-windows-phone/,但没有尝试。
对于iOS我也没有检查http://jfarrell.net/2015/02/25/customizing-the-tab-bar-on-ios-with-xamarin-forms/。