【问题标题】:Android: How to change Action bar background color to dark blue?Android:如何将操作栏背景颜色更改为深蓝色?
【发布时间】:2014-03-31 07:25:05
【问题描述】:

我正在尝试更改我应用的ActionBar背景颜色

我尝试了以下更改,

Reference link

在 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>

然后,

清单文件,我为特定的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>

发生的情况是,整个活动视图的背景变为蓝色,而不是仅更改操作栏的颜色。

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

【问题讨论】:

  • 试试我的答案。像我提到的那样,用 0x 和颜色十六进制值添加你的颜色代码。
  • 你得到答案了吗?

标签: android android-actionbar


【解决方案1】:

我把它改成这样的颜色。

你可以试试这个。

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

将此添加到您的活动类中。

【讨论】:

  • 我试过这样,ActionBar actionBar = getActionBar(); actionBar.setBackgroundDrawable(new ColorDrawable(0x00008b));但是,我在此活动布局中看到操作栏的白色背景。
  • 我将值更改为 0xff005fbf,它按预期显示为蓝色。谢谢!
  • 我的变成了透明的。我也很想尝试褪色的动作栏效果,也许有些事情搞砸了。知道我该怎么做@anuruddhika 吗?
【解决方案2】:

在这里创建您的风格:ActionBar Style Generator。将生成一个包含一堆文件的 zip 文件。将它们复制到适当的资源文件夹中。

如果您好奇,可以查看生成的文件,了解如何通过应用程序样式和主题最好地设置操作栏的样式。

【讨论】:

    【解决方案3】:

    在您的活动代码中,您可以将这些指令放入您的onCreate() 方法中:

    getActionBar().setBackgroundDrawable(new ColorDrawable(this.getResources().getColor(resId_color)));
    

    当您的 resid_color 是您的 colours.xml 文件中定义的颜色时。

    【讨论】:

      猜你喜欢
      • 2015-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多