简体   繁体   English

Android:无法设置操作栏的背景颜色

[英]Android:Unable to set background color of Action Bar

I am trying to set background color of action bar which I am unable to do . 我正在尝试设置操作栏的背景颜色,但我无法这样做。

My styles.xml in values-v11 folder is as follows 我在values-v11文件夹中的styles.xml如下

<resources>

    <!--
        Base application theme for API 11+. This theme completely replaces
        AppBaseTheme from res/values/styles.xml on API 11+ devices.
    -->
    <style name="AppBaseTheme" parent="@android:style/Theme.Holo">


                <item name="android:actionBarStyle">@style/MyActionBar</item>

        <!-- API 11 theme customizations can go here. -->
    </style>

    <style name="MyActionBar">
        <item name="android:background">#99DD00</item>
    </style>
</resources>

The problem identified was that styles.xml (v-14) contained an empty tag with same name and it was picking up the theme from there 确定的问题是styles.xml(v-14)包含一个具有相同名称的空标记,并且它从此处拾取主题

<style name="AppBaseTheme" >           
</style>

I am using the below in my application and it works perfectly: 我在我的应用程序中使用以下内容,它可以完美运行:

<resources>

    <!-- Base application theme. -->
    <style name="CustomActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:height">65dp</item>
        <item name="android:background">@android:color/black</item>
    </style>

    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
        <item name="android:actionBarStyle">@style/CustomActionBar</item>    </style>
</resources>

For Android 3.0 and higher only 仅适用于Android 3.0及更高版本

//res/values/themes.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
       parent="@android:style/Theme.Holo.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>

<!-- ActionBar styles -->
<style name="MyActionBar"
       parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@drawable/actionbar_background</item>
</style>
</resources>

For Android 2.1 and higher 对于Android 2.1及更高版本

//res/values/themes.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
       parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/MyActionBar</item>

    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<!-- ActionBar styles -->
<style name="MyActionBar"
       parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@drawable/actionbar_background</item>

    <!-- Support library compatibility -->
    <item name="background">@drawable/actionbar_background</item>
</style>
</resources>

Then apply your theme to your entire app or individual activities: 然后将您的主题应用于整个应用程序或单个活动:

<application android:theme="@style/CustomActionBarTheme" ... />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM