Android:如何将操作栏背景颜色更改为深蓝色?

Ste*_*lla 2 android android-actionbar

我试图改变背景颜色ActionBar我的应用程序.

我尝试了以下更改,

参考链接

在style.xml文件中,我添加了"MyTheme"和"ActionBarBackground",如下所示.

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

然后,

清单文件,我为此特别添加activity如下,

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

会发生什么,它会变为整个活动视图背景的蓝色,而不是仅仅改变操作栏的颜色.

有人可以建议,我在这里做错了什么.

anu*_*ika 5

我改变了它的颜色.

你可以试试这个.

ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(0xFF160203));
Run Code Online (Sandbox Code Playgroud)

在您的活动类中添加此项.