0

I want to change the background colour of the action bar and maybe the text colour too. This question has already asked here but I do not understand it. Do I need to make a new xml file with this:

 <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 where should I save it? what folder? and how to set this as my theme?

Thanks in advance.

Community
  • 1
  • 1
Dan
  • 47
  • 9

3 Answers3

0

You should save this xml into values folder, like themes.xml

<?xml version="1.0" encoding="utf-8"?>
<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 you should select this theme in AndroidManifest like:

<application android:theme="@style/MyTheme">
Bruno Santos
  • 46
  • 1
  • 3
0

Try this way... simple create a new color xml in drawable folder..

somecolor.xml

<?xml version="1.0" encoding="utf-8"?>
<color xmlns:android="http://schemas.android.com/apk/res/android" 
android:color="#e03456">
</color>

then in onCreate:

    getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.somecolor));

if you wish to change text color:

 int titleId = getResources().getIdentifier("action_bar_title", "id","android");
          TextView yourTextView = (TextView) findViewById(titleId);
       yourTextView.setTextColor(getResources().getColor(android.R.color.white));
J.Ajendra
  • 345
  • 1
  • 10
0

Here is how you change the color of Action Bar (only a few steps):

  1. Use Android Action Bar Style Generator to general all style xml for your application. It's a web tool, http://android-ui-utils.googlecode.com/hg/asset-studio/dist/index.html. The web allows you to generate styles (color, background ... etc) necessary for the Action Bar. Here is the screen shot of the web tool. enter image description here
  2. The tool generates sample resources icons, images, style xml as the followings. Add all resource files to the application resource drawable area, and update AndroidManifest.xml application:theme to use the style xml generated from the tool. The following is the sample styles, images created from the tool. enter image description here
  3. I put all xml in res/drawable folder, except for the action bar style file. I put the action bar style file in res/values. The style file contains this line: <style name="Theme.Example" parent="@android:style/Theme.Holo.Light.DarkActionBar">

  4. Update your AndroidManfest.xml to use the action bar style "Theme.Example" in the main activity which has the action bar.

    <activity
        android:theme="@style/Theme.Example"
        android:name="com.example.restaurant.MainActivity"       
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>  
    </activity>
    
  5. The following is the styled action bar I generated for my project. enter image description here

Mei-Lin
  • 286
  • 2
  • 4