本文介绍了Xamarin Forms TabbedPage 标题的中心文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有多个子页面的 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 手机,我发现这篇文章 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 标题的中心文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 05:26