如何更改所选和未选择的标签intablayout的字体?

时间:2015-12-18 07:55:17

标签: android

如何使用font android TabLayout更改所选和未选定标签的support desing library

1 个答案:

答案 0 :(得分:0)

使用此方法更改tablayout的文本字体

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