Change the font of tab text in android design support TabLayout

前端 未结 18 1732
执念已碎
执念已碎 2020-11-27 13:38

I\'m trying to work on the new TabLayout from the android design library.

I want to change tab text to custom font. And,I tried to sear

18条回答
  •  无人及你
    2020-11-27 14:25

    If you are using TabLayout and you want to change the font you have to add a new for loop to the previous solution like this:

    private void changeTabsFont() {
        ViewGroup vg = (ViewGroup) tabLayout.getChildAt(0);
            int tabsCount = vg.getChildCount();
            for (int j = 0; j < tabsCount; j++) {
                ViewGroup vgTab = (ViewGroup) vg.getChildAt(j);
                int tabChildsCount = vgTab.getChildCount();
                for (int i = 0; i < tabChildsCount; i++) {
                    View tabViewChild = vgTab.getChildAt(i);
                    if (tabViewChild instanceof TextView) {
                        ((TextView) tabViewChild).setTypeface(Font.getInstance().getTypeFace(), Typeface.NORMAL);
                    }
            }
        }
    } 
    

    Please refer to change font style in action bar tabs using sherlock

提交回复
热议问题