TabLayout Style Text

I am trying to create a new TabLayout from an Android design library.

 <style name="NavigationTab" parent="Widget.Design.TabLayout"> <item name="tabBackground">@drawable/background_tab</item> <item name="tabIndicatorColor">@color/blue</item> <item name="tabTextAppearance">@style/NavigationTabTextAppeareance</item> </style> 

And the text is defined right here

 <style name="NavigationTabTextAppeareance" parent="TextAppearance.Design.Tab"> <item name="android:textColor">@color/primary_light</item> <item name="android:textSize">12sp</item> </style> 

But the selected tab is always black, how can I change it?

+7
android android-design-library
source share
2 answers

set tabSelectedTextColor to NavigationTab as follows:

 <style name="NavigationTab" parent="Widget.Design.TabLayout"> <item name="tabBackground">@drawable/background_tab</item> <item name="tabSelectedTextColor">@color/primary_light</item> <item name="tabIndicatorColor">@color/blue</item> <item name="tabTextAppearance">@style/NavigationTabTextAppeareance</item> </style> <style name="NavigationTabTextAppeareance" parent="TextAppearance.Design.Tab"> <item name="android:textColor">@color/primary_light</item> <item name="android:textSize">12sp</item> </style> 
+12
source share

If you just need to specify a different text color, then there is a direct option using app: tabTextColor for unselected and applications: tabSelectedTextColor for the selected tab text , as in the example.

 <android.support.design.widget.TabLayout android:layout_width="match_parent" android:layout_height="wrap_content" app:tabTextColor="#607D8B" app:tabSelectedTextColor="#FFFFFF"/> 
+2
source share

All Articles