Give the following a try. Note to implement the tab selected listener as well.
TextView title = (TextView)(((LinearLayout ((LinearLayout) mTabLayout.getChildAt(0)).getChildAt(tabPosition)).getChildAt(1));
title.setTextSize(...);
class OnTabSelectedListener implements TabLayout.OnTabSelectedListener{
@Override
public void onTabSelected(TabLayout.Tab selectedTab) {
LinearLayout tabLayout1 = (LinearLayout)((ViewGroup) tabLayout.getChildAt(0)).getChildAt(selectedTab.getPosition());
TextView tabTextView = (TextView) tabLayout1.getChildAt(1);
// tabTextView.setTypeface(tabTextView.getTypeface(), Typeface.BOLD);
tabTextView.setTextSize(20);
}
@Override
public void onTabUnselected(TabLayout.Tab unselectedTab) {
LinearLayout tabLayout1 = (LinearLayout)((ViewGroup) tabLayout.getChildAt(0)).getChildAt(unselectedTab.getPosition());
TextView tabTextView = (TextView) tabLayout1.getChildAt(1);
//tabTextView.setTypeface(tabTextView.getTypeface(), Typeface.NORMAL);
tabTextView.setTextSize(15);
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
}
Do anything with textview Enjoy....
display bold text
tabLayout.addOnTabSelectedListener(tabSelectedListener)
private val tabSelectedListener = object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab?) {
tab?.view?.children?.forEach {
if (it is TextView) {
it.post {
it.setTypeface(ResourcesCompat.getFont(context, R.font.bold_font_name), Typeface.NORMAL)
}
}
}
}
override fun onTabUnselected(tab: TabLayout.Tab?) {
tab?.view?.children?.forEach {
if (it is TextView) {
it.post {
it.setTypeface(ResourcesCompat.getFont(context, R.font.font_name), Typeface.NORMAL)
}
}
}
}
override fun onTabReselected(tab: TabLayout.Tab?) {}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.