我在 Forms.Droid 上的选项卡栏文本大小方面遇到问题。
It looks like this:
有谁知道如何缩小字体大小来解决这个问题?
Thanks!
您可以使用自定义渲染器 https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/custom-renderer/创建你的渲染器TabbedPage
,然后在渲染器中您可以像这样编写代码:
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
:
如何在 Xamarin.Forms 中 TabbedPage 的选项卡中放置按钮? https://stackoverflow.com/questions/44507091/how-can-i-place-a-button-in-the-the-tabs-of-a-tabbedpage-in-xamarin-forms/44511454#44511454
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)