How to customize the TabbedPage's Tab-Items in Xamarin.Forms?

…衆ロ難τιáo~ 提交于 2019-12-06 00:49:51

You should be looking for a TabLayout, not an ActionBar. Last I checked the TabLayout is the second child in the renderer's view hierarchy so you should be able to get at it like so:

var tabLayout = (TabLayout)GetChildAt(1);

Once you have that you need to loop through the individual tabs and apply your desired font size to each tab's textview.

Helpful hint, the view hierarchy looks like this:

MsiTabbedRenderer
    FormsViewPager
    TabLayout
        SlidingTabStrip
            TabView
                AppCompatImageView
                AppCompatTextView
            TabView
                AppCompatImageView
                AppCompatTextView
            TabView
                AppCompatImageView
                AppCompatTextView
            ...

The method I use to generate this information is included below for your enjoyment:

    public static void DebugLayout(this View self, int indent = 0)
    {
        // write info about me first
        var indents = new string('\t', indent);
        System.Diagnostics.Debug.WriteLine(indents + self.GetType().Name);

        // check if I'm a view group
        var vg = self as ViewGroup;
        if (vg == null) return;

        // enumerate my children
        var children = Enumerable.Range(0, vg.ChildCount).Select(x => vg.GetChildAt(x));

        // recurse on each child
        foreach (var child in children)
            DebugLayout(child, indent+1);
    }

For Custom tab view/page i am using the xam.Tabview (Xamarin.Forms) Component and it's working as expected. It has the support for custom header and content view.

Install Nuget: TabView Nuget

Sample: Tabview Sample

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!