Currently I am trying to style one Tab
in a TabLayout
differently to the rest. I would like one Tab
with a specific index to have red text, both selected and unselected. As I am only requiring this for only one Tab
at a specific index, the usual solution below does not work:
app:tabSelectedTextColor="@color/red"
app:tabTextColor="@color/red"
I have also attempted to apply a Spannable
when returning the title for that specific Tab
, however this doesn't actually display:
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case TAB_ONE:
return getString(R.string.tab_one);
case TAB_TWO_RED:
Spannable spannable = new SpannableString(getString(R.string.tab_two));
spannable.setSpan(new ForegroundColorSpan(Color.RED),
0, getString(R.string.tab_two).length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return spannable;
}
return null;
}
I would appreciate greatly if anyone knew how to style the text for one Tab
with a specified index only.