Search code examples
androidandroid-tabhosttabwidgetandroid-style-tabhost

How to change TabWidget color?



I'm new to Android and I need your help!
I love default tabWidget style, but I need white color in tab title.
This is what I have for now tabwidget
I want "TAB1" and "TAB2" in white color.
I tried my own tabwidget style. Here's the code

<!-- styles.xml -->

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:tabWidgetStyle">@style/LightTabWidget</item>
</style>
<style name="LightTabWidget" parent="@android:style/Widget.TabWidget">
    <item name="android:textColor">@color/tabTitle</item>
</style>

This will change title text color but it change all tab style enter image description here

How I can change text color only? Without changing the rest?
Thanks for the help!

UPDATE I'm using tabHost. Is it possible to do what I need with it not with TabLayout?


Solution

  • put these lines in your xml-

    app:tabSelectedTextColor="@android:color/white"
    app:tabTextColor="@android:color/black"
    
    <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabGravity="fill"
            app:tabMode="fixed"
            app:tabTextAppearance="@style/MyTabLayoutTextAppearance"
            app:tabIndicatorColor="@color/black"
            app:tabSelectedTextColor="@android:color/white"
            app:tabTextColor="@android:color/black"/>