The contents of this post may not apply if you are using a later version of the support library. The support library has since this posts creation changed how it themes components being shown on lollipop.
Additional information can be found here: Android developers blog
In my latest project I had to theme the ActionBar. This always includes some kind of cursing and frustration for me. Even with my learnings from previous projects I still seem to find new things about this that give me headache.
Previously when I have based my themes on the Holo theme I have used an online generator such as Android Holo Colors Generator. On that page you’ll also find information about the available Android Studio plugin. The same plugin can be found from within Android Studio in the plugin manager.
This time around the generator did not suffice since it couldn’t generate styles for the SearchView.
My first instinct was to base my theme on Holo.Light.DarkActionBar. That way I know the widgets in the ActionBar will attain their light version i.e. light text and accents, which is what I want.
The background color was the first obvious feature I needed to change. To achieve this I need to set an ActionBar theme.
If I chose Widget.AppCompat.ActionBar.Solid I got a dark title, which I neither expected nor wanted. To solve this I resorted to using the Widget.AppCompat.Light.ActionBar.Solid.Inverse instead. This works and even though I could have solved it by styling the title I still prefer this approach.
At this point the theme looks like the following:
Not there yet…
As seen in the screenshot above the popup menu still follows the Holo dark theme and we want it to be following the light version. One way to solve this is by adding a ActionBar widget theme. Since the popup is considered a widget applying a custom style here will alter its appearance.
With that applied the theme now looks like this:
Now the ActionBar is themed properly and I’m happy again :)
Below you’ll find the full theme and the final look. Notice that the the text is selected which is why the text background is dark.
Theming in Android is not as easy as I would have wanted. Doing something simple as setting an accent color should be a lot simpler. But why they hide attributes of a standard component such as the SearchView alludes me.