Search code examples
androidandroid-tablayout

Android: tabSelectedTextColor doesn't change text of selected tab in TabLayout


I m trying to change the text Color of the selected tab in Tab Layout. The indicator color works fine, but the tabSelectedTextColor doesn't seems to be working. The color remains white. I am using support library 22.2.1, what am I doing wrong? Is there an alternate way to achieve this

<android.support.design.widget.TabLayout
                android:id="@+id/tab_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/toolbar"
                android:elevation="6dp"
                android:minHeight="?attr/actionBarSize"
                app:tabIndicatorColor="#000000"
                app:tabSelectedTextColor="#000000"
                app:tabMode="scrollable" />

Solution

  • I do not exactly know what is causing your code to not work, but I have got an alternate way to do it.

    The other way to do it is to change the selected tab's color in your code programmatically. You can use the setTabTextColors (int normalColor, int selectedColor) method of the TabLayout (found here) and not only set selected text color but normal text color too.

    So, your code could go something like this:

    yourTabLayout.setTabTextColors (Color.White, Color.Black);
    

    Here are the colors defined.

    I hope this helps you.