Details:
I\'m extending ActionBarActivity.
Eclipse and SDK fully patched as of 2011-11-06.
Use this - http://jgilfelt.github.io/android-actionbarstylegenerator/
Its an amazing tool that lets you customize your actionbar with a live preview.
I tried the earlier answers but always had problems with changing other colors like the tabs and letters and spent hours tweaking stuff. This tool helped me get my design done in just a couple of minutes.
All the best! :)
ActionBar actionbar = getActionBar();
actionbar.setBackgroundDrawable(new ColorDrawable("color"));
ActionBar actionbar = getSupportActionBar();
actionbar.setBackgroundDrawable(new ColorDrawable("color"));
Try this
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable("COLOR"));
Use This code ..to change action bar background color. open "res/values/themes.xml" (if not present, create it) and add
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="@android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@drawable/actionbar_background</item>
</style>
Note : this code works for android 3.0 and higher versions only
This code may be helpful
<!-- 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>
Direct add this line with your color code
getSupportActionBar().setBackgroundDrawable(
new ColorDrawable(Color.parseColor("#5e9c00")));
not need to create ActionBar object every time...