【发布时间】:2014-06-03 01:15:57
【问题描述】:
我在网上发现了一些关于这个问题的问题。不幸的是,到目前为止我尝试的一切都没有成功。
标题说,我需要更改操作栏的背景颜色。
该项目的最小 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" >
但没有任何改变。问题出在哪里?应用程序接受代码,因为如果我改变 ths:
<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>
【问题讨论】:
-
什么版本的android有设备在哪里测试代码?
-
安卓 4.2.2 三星 s2 plus
-
主题总是很棘手。这是一团糟,而且记录不充分。另一方面,您是否需要至少支持 9 的 Android SDK?您将涵盖运行 15 或更高版本的绝大多数设备......只是说......
标签: android xml android-actionbar