我在网上找到一些关于这个问题的问答。不幸的是,迄今为止,我尝试的一切都没有成功。
正如标题所说,我需要更改操作栏的背景颜色。
该项目的最小SDK为9,最大SDK为19。
我在我的res/values文件夹中创建了一个XML文件:
red_actionbar.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">@color/red</item>
</style>
</resources>
存储在res/values中的colors.xml
<resources>
<color name="red">#FF0000</color>
</resources>
我修改主题的清单部分
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/CustomActionBarTheme" >
但是没有任何变化。问题出在哪里?应用程序接受代码,因为如果我更改了这个:
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar ">
它确实改变了我的应用程序的主题,所以问题在于样式,但我不知道如何解决。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
<item name="android:actionBarStyle" tools:ignore="NewApi">@style/MyActionBar</item>
<item name="actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar"
parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background" tools:ignore="NewApi">@color/red</item>
<item name="background">@color/red</item>
</style>
</resources>