细节:

我正在扩展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 actionbar = getActionBar();
actionbar.setBackgroundDrawable(new ColorDrawable("color"));

其他回答

试试这个

ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable("COLOR"));

对于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

这段代码可能会有帮助

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- Customize your theme here. -->
</style>
<style name="Theme.MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- customize the color palette -->
    <item name="colorPrimary">@color/material_blue_500</item>
    <item name="colorPrimaryDark">@color/material_blue_700</item>
    <item name="colorAccent">@color/material_blue_500</item>
    <item name="colorControlNormal">@color/black</item>

</style>
<style name="CardViewStyle" parent="CardView.Light">
    <item name="android:state_pressed">@color/material_blue_700</item>
    <item name="android:state_focused">@color/material_blue_700</item>
    <!--<item name="android:background">?android:attr/selectableItemBackground</item>-->
</style>

这对我来说很管用,AppCompatActivity,

    <item name="actionBarStyle">@style/BlackActionBar</item>
</style>

<style name="BlackActionBar" parent="@style/Widget.AppCompat.ActionBar.Solid">
    <item name="background">@android:color/black</item>
    <item name="titleTextStyle">@style/BlackActionBarTitleTextStyle</item>
</style>

<style name="BlackActionBarTitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
    <item name="android:textColor">@android:color/white</item>
    <item name="android:fontFamily">@font/cinzel_decorative</item>
</style>

对于那些使用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>