I want to make the text of a selected tab bold. How can I do this either through xml or java code, whatever is easier.
This works in JAVA
tabs.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
initTabSelection(tab);
for(int index = 0; index < ((ViewGroup) tab.view).getChildCount(); index++) {
View nextChild = ((ViewGroup) tab.view).getChildAt(index);
if (nextChild instanceof TextView) {
TextView v = (TextView) nextChild;
v.setTypeface(null, Typeface.BOLD);
}
}
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
for(int index = 0; index < ((ViewGroup) tab.view).getChildCount(); index++) {
View nextChild = ((ViewGroup) tab.view).getChildAt(index);
if (nextChild instanceof TextView) {
TextView v = (TextView) nextChild;
v.setTypeface(null, Typeface.NORMAL);
}
}
}
@Override
public void onTabReselected(TabLayout.Tab tab) { }
});