繁体   English   中英

在Android中设置操作栏的背景颜色

[英]Set Background color of Action Bar in Android

您好,我是Android的菜鸟。

我正在使用appcompat支持库来使我的应用程序向后兼容。 在这里,操作栏颜色默认为Light ,我想将背景色更改为自定义颜色。

任何想法如何做到这一点?

styles.xml

<resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

</resources>

在此处输入图片说明

这解决了我的问题。 谢谢@Zohra

ActionBar mActionBar = getActionBar();
mActionBar.setBackgroundDrawable(new ColorDrawable("COLOR"));

您可以尝试使用官方文档中的方法。 我认为这有一个明确的例子。

你的风格可能看起来像这样

参考: -https : //developer.android.com/training/basics/actionbar/styling.html

  <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.Solid.Inverse">

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

暂无
暂无

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

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