将背景颜色设置为 ActionBar 选项卡会删除分隔线

Setting background color to ActionBar tabs removes divider

我使用 Android 操作栏和选项卡,我想更改我的选项卡背景颜色。 我尝试将它应用到我的风格中:

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

它在所有情况下都有效,但分隔线(每个选项卡之间的小条)在孔处被移除。我怎样才能避免这种情况?

您可以定义样式并将其应用到您的应用程序或 activity:

文件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>
    ...

文件color.xml:

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

应用于 AndroidManifest.xml 中的应用:

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