I wanted to try out this funny title bar coloring, but it doesn’t work for me as
getWindow().findViewById(android.R.id.title);
returns null. So I had a look at it with Hierarchy Viewer and found out that the view is called id/action_bar instead. But there’s no R.id.action_bar (autocomplete doesn’t offer it and there’s nothing like this is R.java).
So now I’m doubly confused:
- Is
android.R.id.titlesort of obsolete now (I’m using version 16 in my emulator)? - Where does
id/action_barcome from? - What’s the recommended and simple practice w.r.t. compatibility?
Should I get ActionBarSherlock? I originally just wanted to change the title bar color… not fool around with it a lot.
I would recommend using ActionBarSherlock if you’re looking for compatibility with Android versions before API level 14 / Android 4.0.
Changing the background of the ActionBar is straightforward and is most easily done via styles. See the “Background” section of http://android-developers.blogspot.com/2011/04/customizing-action-bar.html
You can also change it via code. Put this in your
onCreate():Here is a screenshot of this code in action: