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

2023-09-12 03:28:40 作者:懦弱成狗

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

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

我尝试了以下的变化,

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.