7

I know this question has already been asked, but I can't figure out how to get it working. I want to change the background of my title bar.

I don't want to change anything else about the style of my application or of my background.

I followed various post on this site, but none of them seem to give a satisfying result.

I would think it would be as simple as setting

<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowTitleBackgroundStyle">@drawable/backrepeat</item>
</style>

In styles.xml

However this gives no change whatsover.

For completness below is my backrepeat file

<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/bg_diamonds"
android:tileMode="repeat"
android:dither="true" 
/>

and the code in manifest.xml

<application
android:allowBackup="true"
android:icon="@drawable/maxmm_start_icon"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
Tim van Lieshout
  • 103
  • 1
  • 1
  • 6

2 Answers2

24

You can use it when activity created. (onCreate)

ActionBar bar = getActionBar();
//for color
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#00C4CD")));
//for image
bar.setBackgroundDrawable(getResources().getDrawable(R.drawable.settings_icon));
Melih Mucuk
  • 6,988
  • 6
  • 37
  • 56
  • 1
    This works, thanks (Reason I was not doing this was because it requires minimum sdk version, higher than the one i was supporting. But I worked around this.) – Tim van Lieshout Oct 01 '13 at 09:54
  • If you use this to make the ActionBar a certian colour then it affects the ActionBar Overflow icon - any idea how to change this icon to rectify this ? – Ashley James Brown Feb 13 '14 at 17:11
10

You can change your title color using this code add these line in oncreate() :

ColorDrawable colorDrawable = new ColorDrawable(Color.parseColor("#20a780"));
    getSupportActionBar().setBackgroundDrawable(colorDrawable);
Aneh Thakur
  • 1,072
  • 12
  • 20