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.
If you use default TabLayout (not customView), you can get TextView of tab by using getChildAt() method.
.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
LinearLayout tabLayout = (LinearLayout)((ViewGroup) mMainTabs.getChildAt(0)).getChildAt(tab.getPosition());
TextView tabTextView = (TextView) tabLayout.getChildAt(1);
tabTextView.setTypeface(tabTextView.getTypeface(), Typeface.BOLD);
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
LinearLayout tabLayout = (LinearLayout)((ViewGroup) mMainTabs.getChildAt(0)).getChildAt(tab.getPosition());
TextView tabTextView = (TextView) tabLayout.getChildAt(1);
tabTextView.setTypeface(tabTextView.getTypeface(), Typeface.NORMAL);
}
@Override
public void onTabReselected(TabLayout.Tab tab) { }
});