如何使用 XML 更改 ActionBarActivity 的 ActionBar 的背景颜色? [英] How do I change the background color of the ActionBar of an ActionBarActivity using XML?

查看:32
本文介绍了如何使用 XML 更改 ActionBarActivity 的 ActionBar 的背景颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

详情:

我正在扩展 ActionBarActivity.
Eclipse 和 SDK 已于 2011 年 11 月 6 日完全修补.

I'm extending ActionBarActivity.
Eclipse and SDK fully patched as of 2011-11-06.

<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14" />  

部署到搭载 Android 2.3.3 的三星设备
应用程序有 android:theme="@android:style/Theme.Light"

Deployed to Samsung device with Android 2.3.3
Application has android:theme="@android:style/Theme.Light"

问题:应用程序很轻,但 ActionBar 是蓝色的,带有灰色图标,在蓝色背景色下几乎看不到.我还希望 ActionBar 是浅色的,以便它们的灰色图标更显眼.

Issue: application is light, but ActionBar is blue with grey icons, hardly visible against the blue background color. I also want the ActionBar to be light, so they grey icons are more visible.

我尝试过修改样式但无济于事.
我可能错过了一些微不足道的东西.

I've tried modifying the styles but to no avail.
I'm probably missing something trivial.

如何使用 XML 更改 ActionBarActivity 的 ActionBar 的背景颜色?

推荐答案

根据 文档 - 您可以使用 Android 3.0(API 级别 11)中添加的 ActionBar API 控制操作栏的行为和可见性."

As per documentation - "You can control the behaviors and visibility of the action bar with the ActionBar APIs, which were added in Android 3.0 (API level 11)."

因此,ActionBar 不适用于 API 级别 10 (Android 2.3.3) 的目标环境.

So, ActionBar will not work for your target environment which is at API level 10 (Android 2.3.3).

以防万一,如果您的目标是最低 API 级别 11,您可以通过定义自定义样式来更改 ActionBar 的背景颜色,如下所示:

Just in case, if you target for minimum API level 11 , you can change ActionBar's background color by defining custom style, as:

<resources>
    <style name="MyTheme" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

    <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">ANY_HEX_COLOR_CODE</item>
    </style>
</resources>

并且,将MyTheme"设置为应用程序/活动的主题.

And, set "MyTheme" as theme for application / activity.

这篇关于如何使用 XML 更改 ActionBarActivity 的 ActionBar 的背景颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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