Search code examples
androidtabsandroid-text-color

Custom unselected tab text color in SlidingTabLayout


I am using the SlidingTabLayout class to display tabs in my Android application.

I'm using my custom tab view which I set with the setCustomTabViewfunction. Although I can easily customize the selected tab text color, I can not find a way to customize the text color of the unselected tab. In the L preview documentation they suggest that it should be #fff 60%, and I want to use that exact same value also. I looked at the SlidingTabLayout and SlidingTabStrip classes, but could not figure out where should I make modifications.


Solution

  • The answer turned out to be quite simple, actually.. I don't know why I did not think of it sooner..

    For everybody who wonder, you should simply create tab_text.xml in the res/colors folder, with content:

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:color="@android:color/selected" android:state_selected="true" />
        <item android:color="@android:color/unselected" />
    </selector>
    

    And then set the defined xml (tab_text.xml) to the textColor attribute of the custom tab view (in my case the custom view is a simple TextView).