Search code examples
androidandroid-actionbarandroid-actionbar-tabs

Setting background color to ActionBar tabs removes divider


I use Android actionbar and tabs and I want to change my tabs background color. I tried to apply it to the following in my style:

Widget.AppCompat.ActionBar
Widget.AppCompat.ActionBar.TabBar
Widget.AppCompat.ActionBar.TabView
Widget.AppCompat.ActionBar.Solid

It works in all cases, but dividers (little bars between each tab) are removed at the well. How can I avoid this?


Solution

  • You could define a style and apply it to your app or activity:

    File styles.xml:

    <style name="MyHoloLightTheme" parent="@style/Theme.AppCompat.Light">
        <item name="actionBarStyle">@style/ActionBarStyle</item>
        ....
    <style name="ActionBarStyle" parent="...">
        <item name="background">@color/actionBarBackgroundColor</item>
        ...
    

    File color.xml:

    <color name="actionBarBackgroundColor">#00ff00</color>
    

    Apply to app in AndroidManifest.xml:

    <application
        ...
        android:theme="@style/MyHoloLightTheme"
        ...