-3

How to Change color in action bar background color using programatically in android

Using setBackgroundDrawable this property.

Vishal Ginoya
  • 42
  • 1
  • 11
  • Check this [link](http://stackoverflow.com/questions/8024706/how-do-i-change-the-background-color-of-the-actionbar-of-an-actionbaractivity-us?answertab=active#tab-top) – W I Z A R D Sep 24 '14 at 07:48

4 Answers4

2

There are 2 methods.


Method 1 -

In res/values/styles.xml, you can define it like this -

For Android 3.0 and higher

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

<style name="MyActionBar"
       parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:background">ANY IMAGE OR HEX COLOR</item>
</style>

For Android 2.1 and higher

<style name="CustomActionBarTheme"
       parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/MyActionBar</item>

    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/MyActionBar</item>
</style>

<!-- ActionBar styles -->
<style name="MyActionBar"
       parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@drawable/actionbar_background</item>

    <!-- Support library compatibility -->
    <item name="background">@drawable/actionbar_background</item>
</style>

Then apply your theme to your entire app or individual activities:

android:theme="@style/CustomActionBarTheme"

Method 2 -

To change it programaically, try this -

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

Docs - Styling the Action Bar

Confuse
  • 5,646
  • 7
  • 36
  • 58
1

You have already mentioned method in your question

Use it as:

ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("##CC66FF")));

Hope this helps.

MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124
0
       ActionBar ab = getActionBar(); 
       ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#81a3d0"));     
       ab.setBackgroundDrawable(colorDrawable);

have look this also

Naveen Tamrakar
  • 3,349
  • 1
  • 19
  • 28
0

you can use a ColorDrawable

 ColorDrawable colorDrawable = new ColorDrawable();
 colorDrawable.setColor(yourColor);
Blackbelt
  • 156,034
  • 29
  • 297
  • 305