问题描述
我需要为活动和非活动选项卡设置不同的文本大小,但我只知道如何像这样更改所有选项卡的文本大小
<style name="TextTabLayout" parent="TextAppearance.MaterialComponents.Button">
<item name="android:textAllCaps">false</item>
<item name="android:textSize">26sp</item>
</style>
但是有没有办法为活动和非活动标签设置不同的文本大小?
解决方法
您可以在 onTabSelected() 中设置标签大小。 像这样
mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
((TextView) tab.getCustomView().findViewById(R.id.text1)).setTextSize(16);
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
((TextView) tab.getCustomView().findViewById(R.id.text1)).setTextSize(13);
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});