【问题标题】:Change text size of active or inactive tab in Android更改 Android 中活动或非活动选项卡的文本大小
【发布时间】:2021-05-23 05:23:06
【问题描述】:
我需要为活动和非活动选项卡设置不同的文本大小,但我只发现了如何更改所有选项卡的文本大小
<style name="TextTabLayout" parent="TextAppearance.MaterialComponents.Button">
<item name="android:textAllCaps">false</item>
<item name="android:textSize">26sp</item>
</style>
但是有没有办法为活动和非活动标签设置不同的文本大小?
【问题讨论】:
标签:
android
android-studio
android-layout
android-tablayout
text-size
【解决方案1】:
您可以在 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) {
}
});