-1

How to change Font type of android.support.design.widget.TabLayout?

I'm using style for this problem but app crashes in API 16. Thank you.

MansoorJafari
  • 33
  • 2
  • 6
  • you must create custom layout which contains textview and adapter for tablayout. – Vishal Patoliya ツ Aug 03 '16 at 09:21
  • please post your code and error – Linh Aug 03 '16 at 09:22
  • after I want use this code in style.xml crashes app in api 16 `` – MansoorJafari Aug 03 '16 at 09:29

2 Answers2

0

I found this way:

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);
                }
            }
        }
    } 

Mentioned on this article: Change the font of tab text in android design support TabLayout

Community
  • 1
  • 1
xxx
  • 3,315
  • 5
  • 21
  • 40
0

Try this code:

private void changeTabsFont(TabLayout tabLayout) {

    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(/* your typeface */);
            }
        }
    }
}