是否有人知道如何为textAppearance
中的选定和未选定标签设置不同的TabsLayout
?
documentation仅提及一个适合所有人tabTextAppearance
的{{1}}归因,并且只允许通过tabSelectedTextColor
为所选标签设置不同的颜色。
我的目标是在所选标签上使用不同的字体。
答案 0 :(得分:2)
然后你应该在onTabSelected
接口的OnTabSelectedListener
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
ViewGroup vg = (ViewGroup) tabLayout.getChildAt(0);
ViewGroup vgTab = (ViewGroup) vg.getChildAt(tab.getPosition());
int tabChildsCount = vgTab.getChildCount();
for (int i = 0; i < tabChildsCount; i++) {
View tabViewChild = vgTab.getChildAt(i);
if (tabViewChild instanceof TextView) {
((TextView) tabViewChild).setTypeFace(TYPE_FACE);
}
}
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
ViewGroup vg = (ViewGroup) tabLayout.getChildAt(0);
ViewGroup vgTab = (ViewGroup) vg.getChildAt(tab.getPosition());
int tabChildsCount = vgTab.getChildCount();
for (int i = 0; i < tabChildsCount; i++) {
View tabViewChild = vgTab.getChildAt(i);
if (tabViewChild instanceof TextView) {
((TextView) tabViewChild).setTypeFace(TYPE_FACE);
}
}
}
}