Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the background color of the ActionBar of an ActionBarActivity using XML?

Details:

I'm extending ActionBarActivity.
Eclipse and SDK fully patched as of 2011-11-06.

<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14" />   

Deployed to Samsung device with Android 2.3.3
Application has android:theme="@android:style/Theme.Light"

Issue: application is light, but ActionBar is blue with grey icons, hardly visible against the blue background color. I also want the ActionBar to be light, so they grey icons are more visible.

I've tried modifying the styles but to no avail.
I'm probably missing something trivial.

How do I change the background color of the ActionBar of an ActionBarActivity using XML ?

like image 612
user77115 Avatar asked Nov 06 '11 01:11

user77115


People also ask

How can change background color of button in Android xml?

To set Android Button background color, we can assign android:backgroundTint XML attribute for Button in layout file with the required Color Value. To programmatically set or change Android Button background color, we may call pass the method Button.


2 Answers

As per documentation - "You can control the behaviors and visibility of the action bar with the ActionBar APIs, which were added in Android 3.0 (API level 11)."

So, ActionBar will not work for your target environment which is at API level 10 (Android 2.3.3).

Just in case, if you target for minimum API level 11 , you can change ActionBar's background color by defining custom style, as:

<resources>     <style name="MyTheme" parent="@android:style/Theme.Holo.Light">         <item name="android:actionBarStyle">@style/MyActionBar</item>     </style>      <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">         <item name="android:background">ANY_HEX_COLOR_CODE</item>     </style> </resources> 

And, set "MyTheme" as theme for application / activity.

like image 58
lupchiazoem Avatar answered Oct 08 '22 08:10

lupchiazoem


Try this

ActionBar bar = getActionBar(); bar.setBackgroundDrawable(new ColorDrawable("COLOR")); 
like image 38
coder_For_Life22 Avatar answered Oct 08 '22 10:10

coder_For_Life22