Xamarin Forms更改标签栏大小

时间:2017-10-01 14:13:45

标签: c# android forms xamarin

我在Forms.Droid上使用Tabbar的文本大小时遇到​​问题。

看起来像这样: enter image description here

有谁知道如何缩小字体大小,从而解决了这个问题?

谢谢!

2 个答案:

答案 0 :(得分:2)

您可以使用Custom RenderersTabbedPage创建渲染器,然后在渲染器中编码,例如:

public class StyledTabbedPageRenderer : TabbedPageRenderer
{
    private Android.Views.View formViewPager = null;
    private TabLayout tabLayout = null;

    protected override void OnElementChanged(ElementChangedEventArgs<TabbedPage> e)
    {
        base.OnElementChanged(e);

        this.tabLayout = (TabLayout)this.GetChildAt(1);

        changeTabsFont();
    }

    private void changeTabsFont()
    {
        //Typeface font = Typeface.CreateFromAsset(Android.App.Application.Context.Assets, "fonts/" + Constants.FontStyle);
        ViewGroup vg = (ViewGroup)tabLayout.GetChildAt(0);
        int tabsCount = vg.ChildCount;
        for (int j = 0; j < tabsCount; j++)
        {
            ViewGroup vgTab = (ViewGroup)vg.GetChildAt(j);
            int tabChildsCount = vgTab.ChildCount;
            for (int i = 0; i < tabChildsCount; i++)
            {
                Android.Views.View tabViewChild = vgTab.GetChildAt(i);
                if (tabViewChild is TextView)
                {
                    //((TextView)tabViewChild).Typeface = font;
                    ((TextView)tabViewChild).TextSize = 6;

                }
            }
        }
    }
}

您还可以参考我关于自定义TabbedPage的其他案例:

How can I place a button in the the tabs of a TabbedPage in Xamarin.Forms?

答案 1 :(得分:1)

我认为您需要自定义样式并更改选项卡中的文本大小。

类似的东西:

<style name="MyTab" parent="@android:style/Widget.Holo.ActionBar.TabText">
    <item name="android:textSize"></item>
</style>