2016-08-03 180 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