0

why am I not able to set the textcolor of the tablayout?

Here is the whole xml-source. The relevant line is:

 app:tabTextColor="@color/tabTextColor"

The text is not white - its black

And here is the whole source coude

 <?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"


 xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/linlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include layout="@layout/toolbar"/>

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#4f83cc"
        app:tabMode="scrollable"
        app:tabIndicatorColor="#FFFFFF"
        app:tabTextColor="@color/tabTextColor"
        >
    </android.support.design.widget.TabLayout>


    <android.support.v4.view.ViewPager

        android:id="@+id/viewPager"
        android:layout_below="@+id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        />

and in the color-xml file:

 <?xml version="1.0" encoding="utf-8"?>
<resources>
   <color name="colorPrimary">#01579b</color>
   <color name="colorPrimaryDark">#002f6c</color>
   <color name="colorAccent">#FF4081</color>
   <color name="tabTextColor">#FFFFFF</color>
</resources>
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
java
  • 1,165
  • 1
  • 25
  • 50

2 Answers2

1

You can chnage text color of TabLayout using java code

tabLayout.setTabTextColors(
  getResources().getColor(R.color.your_unselected_text_color),
  getResources().getColor(R.color.your_selected_text_color)
);

Or You can try custom style for TabLayout

<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
  <item name="tabTextAppearance">@style/MyCustomTabText</item>
  <item name="tabSelectedTextColor">@color/tab_text_act</item>
</style>

<style name="MyCustomTabText" parent="TextAppearance.AppCompat.Button">
  <item name="android:textSize">14sp</item>
  <item name="android:textColor">@color/tab_text</item>
</style>

and here is code

<android.support.design.widget.TabLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/MyCustomTabLayout" />
Rohit Chauhan
  • 1,119
  • 1
  • 12
  • 30
  • I've tried but get Error inflating class android.support.design.widget.TabLayout – java Apr 04 '18 at 16:30
  • well I may accept this answer since it worked after moving the style to my values-21 folder. I can see at android.developer that TabLayout was added in API 22. thanks and I cannot see WHY my question was marked as duplicate - look now, my new question about the same issue solved the problem!!!! – java Apr 04 '18 at 16:49
0

Try this :

     app:tabSelectedTextColor="@color/white"
     app:tabIndicatorColor="@color/white"

If it still doesn't work do it programmatically : https://www.stackoverflow.com/a/36962857

I hope this helps you.

Anonymous
  • 2,184
  • 15
  • 23