-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTabLayout 选中加粗
30 lines (27 loc) · 1.23 KB
/
TabLayout 选中加粗
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
tablayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
if (tab == null || tab.getText() == null) {
return;
}
String trim = tab.getText().toString().trim();
SpannableString spStr = new SpannableString(trim);
StyleSpan styleSpan_B = new StyleSpan(Typeface.BOLD);
spStr.setSpan(styleSpan_B, 0, trim.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
tab.setText(spStr);
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
if (tab == null || tab.getText() == null) {
return;
}
String trim = tab.getText().toString().trim();
SpannableString spStr = new SpannableString(trim);
StyleSpan styleSpan_B = new StyleSpan(Typeface.NORMAL);
spStr.setSpan(styleSpan_B, 0, trim.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
tab.setText(spStr);
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});