无法在Android Studio中更改操作栏的背景

时间:2015-02-18 06:59:12

标签: android-actionbar

我想更改操作栏的背景但它不起作用。代码很简单:

<style name="AppTheme" parent="@style/Theme.AppCompat.Light">
    <!-- Customize your theme here. -->
    <item name="android:actionBarStyle">@style/ActionBarTheme</item>
</style>

<style name="ActionBarTheme"
parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@drawable/green1</item>
    <item name="background">@drawable/green1</item>
</style>

<activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">
</activity>

green1是可绘制的图片。我运行程序,操作栏显示为默认主题而不是我想要的图片。问题是什么?真的很困惑。

1 个答案:

答案 0 :(得分:0)

由于您的AppTheme使用parent="@style/Theme.AppCompat.Light">,您的ActionBarTheme应该使用:

<style name="ActionBarTheme"
       parent="@style/Widget.AppCompat.Light.ActionBar">
       ... ...
</style>

取代:

<style name="ActionBarTheme"
       parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
       ... ...
</style>

其他如果您的AppTheme使用DarkActionBar,那么ActionBarTheme使用Solid.Inverse就可以了

相关问题