记录帖,菜鸡想到的办法
private SpannableString getNormalText(String text) {
SpannableString spannableString = new SpannableString(text);
spannableString.setSpan(new AbsoluteSizeSpan(13, true),
0, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return spannableString;
}
private SpannableString getBiggerText(String text) {
SpannableString spannableString = new SpannableString(text);
spannableString.setSpan(new AbsoluteSizeSpan(16, true),
0, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return spannableString;
}
binding.tabHomeFunction.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
int position = tab.getPosition();
String text = list.get(position);
tab.setText(getBiggerText(text));
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
int position = tab.getPosition();
String text = list.get(position);
tab.setText(getNormalText(text));
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
new TabLayoutMediator(binding.tabHomeFunction, binding.viewpager2, (tab, position) -> {
tab.setText(getNormalText(list.get(position)));
}).attach();