Changing The Title Bar Background

I recently ran into an issue when trying to customize the title bar background of an application. Specifically I could get it to work on older versions of Android but not on the new Holo Themes. Knowing the solution now I can tell you…

It’s a silly issue. I blame myself for having spent much time on it, but as I was unable to find a solution when searching for one on the usual channels I will provide it here.

First things first you need to have a custom theme declared for your application (or activity, depending on your needs). Something like…

Then, declare your custom theme for two cases, API versions with and without the Holo Themes. For the old themes we’ll customize the windowTitleBackgroundStyle attribute, and for the newer ones the ActionBarStyle.

That’s it! Here we use @color/title_background as a background. It could also be a drawable, and you can also customize other attributes (I had to set a padding for my WindowTitleBackground style for instance).