Give text of selected tab a different color using ViewPagerIndicator Give text of selected tab a different color using ViewPagerIndicator android android

Give text of selected tab a different color using ViewPagerIndicator


Assuming you don't mind creating an extra xml, first try include the attribute android:textColor in your CustomTabPageIndicator.Text (or CustomTabPageIndicator) like this:

<style name="CustomTabPageIndicator.Text" parent="android:TextAppearance.Medium">    <item name="android:textColor">@drawable/tab_text_color</item>    ...</style>

where tab_text_color.xml is put under res/drawable folder:

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item        android:state_selected="true"        android:color="@color/text_tab_selected" />    <item        android:state_selected="false"        android:color="@color/text_tab_unselected" /></selector>

Finally, just define the two colors @color/text_tab_selected and @color/text_tab_unselected in your color resource file colors.xml located in res/values folder (create one if it does not exist already). For example:

<?xml version="1.0" encoding="utf-8"?><resources>    <color name="text_tab_selected">#FF000000</color>    <color name="text_tab_unselected">#FF555555</color></resources>


Try this

Simplest way

<android.support.design.widget.TabLayout                xmlns:app="http://schemas.android.com/apk/res-auto"                android:id="@+id/tabs"                android:layout_width="match_parent"                android:layout_height="wrap_content"                app:tabTextColor="@color/White"                app:tabSelectedTextColor="@color/Blue"                app:tabIndicatorColor="@color/Yellow"                app:tabMode="fixed"                app:tabGravity="fill"/>

Don't forgot to add this Dependency

compile 'com.android.support:design:23.1.1'