How to Change color in action bar background color using programatically in android
Using setBackgroundDrawable this property.
How to Change color in action bar background color using programatically in android
Using setBackgroundDrawable this property.
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
You have already mentioned method in your question
Use it as:
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("##CC66FF")));
Hope this helps.
ActionBar ab = getActionBar();
ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#81a3d0"));
ab.setBackgroundDrawable(colorDrawable);
you can use a ColorDrawable
ColorDrawable colorDrawable = new ColorDrawable();
colorDrawable.setColor(yourColor);