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.
I know this is an old question, but I came up with a nicer solution:
I created this OnTabSelectedListener
class OnTabSelectedBoldListener : TabLayout.OnTabSelectedListener {
override fun onTabReselected(tab: TabLayout.Tab) {}
override fun onTabUnselected(tab: TabLayout.Tab) {
val views = arrayListOf()
tab.view.findViewsWithText(views, tab.text, View.FIND_VIEWS_WITH_TEXT)
views.forEach { view ->
if (view is TextView) {
TextViewCompat.setTextAppearance(view, R.style.TabTextAppearance)
}
}
}
override fun onTabSelected(tab: TabLayout.Tab) {
val views = arrayListOf()
tab.view.findViewsWithText(views, tab.text, View.FIND_VIEWS_WITH_TEXT)
views.forEach { view ->
if (view is TextView) {
TextViewCompat.setTextAppearance(view, R.style.TabTextAppearance_Selected)
}
}
}
}