简体   繁体   English

在Xamarin标签式页面模板中更改标签栏大小

[英]Change tabbar size in xamarin tabbed page template

I have spent 2 days searching for an answer to this and I just can't find the solution. 我花了2天的时间寻找答案,但找不到解决方案。 All I am trying to do is change the size of the "Tabbar" in android for the template that uses sliding tabs. 我想要做的就是为使用滑动选项卡的模板更改android中“标签栏”的大小。 I have tried using a custom renderer, styles, setting it programatically and nothing will achieve what I want. 我尝试使用自定义渲染器,样式,以编程方式进行设置,但没有任何东西可以实现我想要的功能。 I am able to however change the size of the slider, the font and everything else but changing the height of the tabbar in the tabbedpage is seemingly impossible. 但是,我能够更改滑块的大小,字体和其他所有内容,但是在选项卡页中更改选项卡栏的高度似乎是不可能的。 If anyone has any solutions to this, please feel free to let me know. 如果有人对此有任何解决方案,请随时告诉我。 I can do it if I set up the project outside of Xamarin.forms but I am really trying to keep a good cross platform solution up rather than making multiple for iOS and Android. 如果我在Xamarin.forms之外设置项目,我可以做到,但我实际上是在努力保持良好的跨平台解决方案,而不是为iOS和Android制作多个。

Try using the following code: 尝试使用以下代码:

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;

                }
            }
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM