fun TabLayout.TabView.getTextView():TextView{
val tabClass = TabLayout.TabView::class.java
var declaredField = tabClass.getDeclaredField("textView")
declaredField.isAccessible=true
var textView = declaredField.get(this) as TextView
return textView
}
使用:
override fun initData() {
train_tab.setOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab) {
var textView = tab.view.getTextView()
textView.textSize=24f
textView.paint.isFakeBoldText=true
}
override fun onTabUnselected(tab: TabLayout.Tab) {
var textView = tab.view.getTextView()
textView.textSize=16f
textView.paint.isFakeBoldText=false
}
override fun onTabReselected(tab: TabLayout.Tab?) {
}
})
}
网友评论