Xamarin Forms TabbedPage标题的中心文本 [英] Center text of a Xamarin Forms TabbedPage Title
问题描述
我有一个TabbedPage,其中有多个子页面,每个子页面都有一个标题. 当标题足够短以至于只有一行时,文本将完美居中,但是只要文本需要多于1行,它将不再居中.
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?
推荐答案
我认为不可能对所有平台都采用通用方式,而您必须采用特定于平台的方式.
I think it's impossible to do in common way for all platforms, and you have to do it in platform specific way.
对于android项目,我这样做的方式是: 在文件夹Resources/values中的Styles.xml文件中,我添加了样式
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>
在MainActivity.cs中,我添加了
And in MainActivity.cs I added
[Activity(Theme = "@style/CustomTheme")]
对于Windows Phone,我发现了这篇文章 https://nocture.dk/2014/12/10/xamarin-forms-customizing-tabbed-page-header-title-windows-phone/,但没有尝试.
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.
对于iOS,我也没有检查 http://jfarrell.net/2015/02/25/customizing-the-tab-bar-on-ios-with-xamarin-forms/.
For iOS i didn't check too http://jfarrell.net/2015/02/25/customizing-the-tab-bar-on-ios-with-xamarin-forms/.
这篇关于Xamarin Forms TabbedPage标题的中心文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!