相关疑难解决方法(0)

使用AppCompat更改操作栏的背景颜色

我在网上发现了一些关于这个问题的问题.不幸的是,到目前为止我所尝试的一切都没有成功.

有标题说,我需要更改我的操作栏的背景颜色.

该项目的最小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>
Run Code Online (Sandbox Code Playgroud)

colors.xml存储在res/values中

<resources>
    <color name="red">#FF0000</color>
</resources>
Run Code Online (Sandbox Code Playgroud)

以及我改变主题的清单部分

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/CustomActionBarTheme" >
Run Code Online (Sandbox Code Playgroud)

但没有变化.问题出在哪儿?应用程序接受代码,因为如果我改变了:

<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
Run Code Online (Sandbox Code Playgroud)

<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar ">
Run Code Online (Sandbox Code Playgroud)

它确实改变了我的应用程序的主题,所以问题在于风格,但我不知道如何解决它.

<?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>
Run Code Online (Sandbox Code Playgroud)

xml android android-actionbar

45
推荐指数
3
解决办法
6万
查看次数

标签 统计

android ×1

android-actionbar ×1

xml ×1