Всем привет. Как можно сменить (а можно ли) шрифт текста в TabLayout
и TabItem
в Android приложении?
1 ответ
Сменить шрифт у табов можно так:
public static void changeTabsFont(Context context, TabLayout tabLayout, int color) {
ViewGroup vg = (ViewGroup) tabLayout.getChildAt(0);
tabLayout.setBackgroundColor(color);
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(Typeface.createFromAsset(context.getAssets(), "YoursAwersomeFont.ttf"));
}
}
}
}