细节:

我正在扩展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.parseColor("#0000ff")));

这段代码可能会有帮助

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

当您扩展活动时,请使用以下代码

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

当你扩展AppCompatActivity时,使用下面的代码

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

如果你正在使用androidx AppCompact。使用下面的代码。

androidx.appcompat.app.ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable("Color"));

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

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

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

祝你一切顺利!:)