细节:

我正在扩展ActionBarActivity。 Eclipse和SDK已于2011-11-06完全补丁。

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

部署到三星设备的Android 2.3.3 应用程序有android:theme="@android:style/ theme。光”

问题:应用程序很轻,但ActionBar是蓝色的灰色图标,在蓝色背景色下几乎看不见。我还想让动作栏变得更轻,这样它们的灰色图标就更明显了。

我试过修改样式,但没有用。 我可能遗漏了一些小事。

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


当前回答

根据文档-“你可以用ActionBar API控制操作栏的行为和可见性,这是在Android 3.0 (API级别11)中添加的。”

因此,ActionBar将不能工作于API级别10 (Android 2.3.3)的目标环境。

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

<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”为应用程序/活动的主题。

其他回答

对于那些使用API 21或更高版本的人来说,使用下面的代码非常简单

暗动作栏

<resources>
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="android:background">@color/colorDarkGrey</item>
</style>

for_LightActionBar

<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.ActionBar">
    <item name="android:background">@color/colorDarkGrey</item>
</style>

对于Nexus 4用户来说,这似乎会让颜色变成灰色。

ActionBar bar = getActionBar(); // or MainActivity.getInstance().getActionBar()
bar.setBackgroundDrawable(new ColorDrawable(0xff00DDED));
bar.setDisplayShowTitleEnabled(false);  // required to force redraw, without, gray color
bar.setDisplayShowTitleEnabled(true);

(所有的功劳都归功于这篇文章,但它被淹没在评论中,所以我想在这里展示它) https://stackoverflow.com/a/17198657/1022454

使用这个- http://jgilfelt.github.io/android-actionbarstylegenerator/

这是一个惊人的工具,让你自定义你的动作栏与实时预览。

我尝试了之前的答案,但总是有问题,改变其他颜色,如标签和字母,并花了几个小时调整东西。这个工具帮助我在几分钟内完成了我的设计。

祝你一切顺利!:)

用这个就行了。

ActionBar actionbar = getActionBar();
actionbar.setBackgroundDrawable(new ColorDrawable("color"));

我也遇到了同样的问题,当我输入代码时,我的动作栏会变成灰色。你最初的样式表可能是这样的:

<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    <!-- API 14 theme customizations can go here. -->
</style>

“DarkActionBar”是让你的动作栏保持灰色的。我把它改成了这个,很管用:

<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
    <!-- API 14 theme customizations can go here. -->
    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:background">#2aa4cd</item>
    <item name="android:titleTextStyle">@style/Theme.MyAppTheme.ActionBar.TitleTextStyle</item>
</style>        

<style name="Theme.MyAppTheme.ActionBar.TitleTextStyle" parent="android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">#FFFFFF</item>
</style>    

我还介绍了如何编辑文本颜色。同样,不需要改变资源周围的任何东西。