如何使用Appcompat改变动作栏背景颜色?

问题描述 投票:0回答:1

是的,我知道网上有很多类似的问题和答案。在过去的三个小时里,我检查了所有的问题和答案。没有任何解决方案对我有效。

我只是简单地启动了一个Android Studio(v1.0.2)项目,它是由v7 AppCompat库默认提供的。

我把style.xml改成了:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyAppTheme" parent="Theme.AppCompat.Light">
        <item name="actionBarStyle">@style/MyActionBar</item>
    </style>
    <style name="MyActionBar" parent="@style/MyAppTheme">
        <item name="android:background">@android:color/holo_red_dark</item>
    </style>
</resources>

...然后在AndroidManifest.xml里面:

android:theme="@style/MyAppTheme"

我在寻找一种最简单的方法来改变全局动作栏的背景颜色,使其变成所需的颜色。

现在动作栏完全是白色的,菜单按钮有三个黑点。

android android-actionbar android-support-library background-color android-appcompat
1个回答
0
投票

用Appcompat rel 21.0.x只是使用类似的东西。

<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">

    <!-- Set AppCompat’s color theming attrs -->
    <item name=”colorPrimary”>@color/my_color</item>
    <item name=”colorPrimaryDark”>@color/my_color_darker</item>

</style>

如果你想覆盖 actionBarStyle 属性的使用。

<style name="Theme.MyTheme" parent="Theme.AppCompat.Light">
    <!-- ... -->
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar">
     <!-- default value is @null -->
     <item name="background">....</item>   
</style>
© www.soinside.com 2019 - 2024. All rights reserved.