Martin Seal Martin Seal - 4 days ago 4x
Android Question

Android how can i change the tab color from style or theme

Hi just as the title suggests I'm sure this should be simple but alas it isn't working for me, I'm not looking for anything fancy like onTabSelected etc I just want to set the color of the entire widget based on the theme, right now im trying to do the following, which I'm not sure if is correct but its not working,

It looks like this is what I need

<item name="tabBackground">@color/colorPinkPrimary</item>

but I've tried adding this to my theme in 2 ways and neither work, the first way was to just add this directly to my theme as it is but no joy, the second way I tried was to add another theme

<style name="CustomTabLayoutStylePink" parent="Base.Widget.Design.TabLayout">
<item name="tabSelectedTextColor">@color/selected_textPink</item>
<item name="tabIndicatorColor">@color/colorPinkAccent</item>
<item name="tabTextAppearance">@style/CustomTabTexStylePink</item>
<item name="tabBackground">@color/colorPinkPrimary</item>

and reference it from my theme like this (just to reiterate i dont know if this is best practice or even feasible, it just looked right)

<item name="android:tabWidgetStyle">@style/CustomTabLayoutStylePink</item>

one that does work is

<item name="android:background">@color/colorPinkPrimary</item>

but this also works for every view in my entire app even down to the preference activity textviews and such can anybody help me here


tabBackground should be in your XML file and not inside the style.