有人可以帮我理解为什么这段代码没有将Android Action Bar变成黄色?

时间:2014-03-23 22:03:26

标签: android android-styles android-actionbar-compat

我按照Google's tutorial更改操作栏的颜色并编写了如下所示的代码,但操作栏仍按照Holo Light主题显示。

styles.xml:

    <style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">

    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">

    <!-- Support library compatibility -->
    <item name="background">@color/yellow</item>
</style>

Android Manifest:

    <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Theme.AppCompat.Light" >
    <activity
        android:name="com.example.labside.MainActivity"
        android:label="@string/app_name"
        android:theme="@style/CustomActionBarTheme" >

colors.xml的黄色定义为#FFFF00。请让我知道我做错了什么,因为有关支持API级别8的Action Bar样式的整个内容开始变得非常混乱!一如既往,非常感谢您的帮助! :)

1 个答案:

答案 0 :(得分:0)

你使用的是哪个Android版本?看一下这篇文章:custom style action bar not working in android 4

在这篇文章之后,您需要两次声明自定义样式。看起来你错过了带有android:前缀的声明。

所以我想,你必须补充:

<item name="android:background">@color/yellow</item>