Xamarin Forms更改标签栏大小 [英] Xamarin Forms change the tabbar size
本文介绍了Xamarin Forms更改标签栏大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法使用Forms.Droid上的Tabbar的文本大小.
Im having trouble with the text size of my Tabbar on Forms.Droid.
它看起来像这样:
有人知道如何缩小字体大小,从而解决此问题吗?
Does anyone know how to make the fontsize smaller, thus fixing this issue?
谢谢!
推荐答案
您可以使用自定义渲染器来为TabbedPage
创建渲染器,然后在渲染器中进行如下编码:
You can use Custom Renderers to create your renderer for TabbedPage
, and then in the renderer you can code for example like this:
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
的其他案例:
You can also refer to my other case about customize TabbedPage
: