TabLayout default style for TextView uses TextAppearance with the textAllCaps attribute set to true . The conversion method for this treats CharSequence as a flat String , so any Spannable information is lost.
To prevent this, we can create a style for TabLayout that disables textAllCaps . For instance:
<style name="TabTextAppearance" parent="TextAppearance.Design.Tab"> <item name="textAllCaps">false</item> </style>
Setting this parameter as tabTextAppearance to TabLayout will allow your SpannableString to work as expected.
<android.support.design.widget.TabLayout android:id="@+id/tab_layout" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabTextAppearance="@style/TabTextAppearance" />
As mentioned in the comments, using a custom View for tabs is another option, since by default this option will not have a problem attribute.
source share