2016-08-03 146 views
-1

如何更改android.support.design.widget.TabLayout的字体类型?如何更改Tablayout字体大小

我对此问题使用样式,但应用程序在API 16中崩溃。 谢谢。

+0

必须创建其中包含的TextView和适配器tablayout自定义布局。 –

+0

请发布您的代码和错误 –

+0

我想在style.xml中使用此代码崩溃API中的应用程序16'' – MansoorJafari

回答

0

我发现这种方式:

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

提到这篇文章:Change the font of tab text in android design support TabLayout

+0

谢谢。但不工作----- Font.getInstance()。getTypeFace()我不是这个代码 – MansoorJafari

0

试试这个代码:

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 */); 
      } 
     } 
    } 
} 
+0

谢谢。但不工作 – MansoorJafari