How to Change Text Color of tab Layout?

Try with it -

<android.support.design.widget.TabLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="fixed"
        app:tabGravity="fill"
        android:background="@color/colorWhite"
        app:tabTextColor="@color/colorBlack"
        app:tabSelectedTextColor="@color/colorPrimary"/>

Use this code it would help in all api level api 18 to api 26

tabLayout.setupWithViewPager(viewPager,true);
        tabLayout.setSelected(true);

        tabLayout.setTabTextColors(getResources().getColor(R.color.colorHintTextLight),
                  getResources().getColor(R.color.colorPrimaryTextLight));

<color name="colorHintTextLight">#80FFFFFF</color>
    <color name="colorPrimaryTextLight">#FFFFFF</color>

that would help u.it helps me when tab layout change the position.


You can customize your TabLayout's text.

Create a TextView from Java Code or XML like this

<?xml version="1.0" encoding="utf-8"?>
<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:textSize="15sp"
    android:textColor="@color/tabs_default_color"
    android:gravity="center"
    android:layout_height="match_parent"
/>

Make sure to keep the id as it is here because the TabLayout check for this ID if you use custom TextView

Then from code inflate this layout and set the custom Typeface on that TextView and add this custom view to the tab.

for (int i = 0; i < tabLayout.getTabCount(); i++) {
    //noinspection ConstantConditions
 TextView tv=(TextView)LayoutInflater.from(this).inflate(R.layout.custom_tab,null)
 tv.setTextColor(customColor)
 tabLayout.getTabAt(i).setCustomView(tv);

}