Android的:如何更改操作栏的背景颜色为深蓝色? [英] Android: How to change Action bar background color to dark blue?

查看:149
本文介绍了Android的:如何更改操作栏的背景颜色为深蓝色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图修改背景颜色动作条我的应用程序的

I am trying to change the background color of the ActionBar of my app.

我尝试了以下的变化,

<一个href="http://stackoverflow.com/questions/8024706/how-do-i-change-the-background-color-of-the-actionbar-of-an-actionbaractivity-us">Reference链接

在style.xml文件,我补充说:MyTheme的和ActionBarBackground像下面。

In style.xml file, I added "MyTheme" and "ActionBarBackground" like below.

    <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="android:Theme.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>
    <style name="MyTheme" parent="AppBaseTheme">
        <item name="android:actionBarStyle">@style/ActionBarBackground</item>
    </style>
    <style name="ActionBarBackground" parent="AppBaseTheme">
        <item name="android:background">#00008b</item>
    </style>

</resources>

然后,

清单文件,我添加了特定的活动如下图所示,

Manifest file, I added for that particular activity like below,

<activity android:name="LoginActivity" android:theme="@style/ActionBarBackground">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

发生的事情是,它改变了以蓝色为整个活动视图的背景,而不是改变颜色只是操作栏。

What happens is, It changes to blue color for the background of entire activity view rather than to change color just to the action bar.

可能有人提醒,我在做什么错在这里。

Could someone advise, what i’m doing wrong here.

推荐答案

我改变了它颜色也赞。

您可以试试这个。

ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(0xFF160203));

在您的活动类添加这一点。

Add this in your activity class.

这篇关于Android的:如何更改操作栏的背景颜色为深蓝色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆