If you’ve ever used the style attribute on a View, you know it can be useful to encapsulate shared styling into a reusable definition. But while styles are local to that view alone, android:theme allows you to override attributes in the Context’s theme for a View and all of its child Views as well. Applying a theme to individual Views was introduced in Android 5.0 Lollipop and AppCompat v22.1.0 (and higher) makes this available to all Views on API 11 and higher.
This is where ThemeOverlays such as ThemeOverlay.AppCompat come in. They are themes built specifically to overlay the base AppCompat theme, changing only certain elements as needed. The ones included by default include:
ThemeOverlay.AppCompat: This is an effectively empty theme that can serve as the basis for any custom ThemeOverlay. Note that it does copy AppCompat attributes such as colorPrimary to the framework android:colorPrimary on API 21+ so don’t forget about it!
ThemeOverlay.AppCompat.Light: A ThemeOverlay that changes background colors, text colors, and highlight colors so that match a Light theme (i.e., light background with dark text)
ThemeOverlay.AppCompat.Dark: A ThemeOverlay that, as you might imagine, changes coloring and text to match a Dark theme (i.e., a dark background with light text)
ThemeOverlay.AppCompat.ActionBar and ThemeOverlay.AppCompat.Dark.ActionBar: ThemeOverlays specific to the ActionBar/Toolbar that also change colorControlNormal to android:textColorPrimary and sets the correct SearchView styling as is expected for those components. These should be used only when you override actionBarTheme in your theme or when set on your Toolbar via android:theme.
So if you’re using a light theme but have a portion of your UI with a dark background, you don’t need to set custom text colors on each view. Just use ThemeOverlay.AppCompat.Dark:
But what if you want to change just one specific attribute, say, colorAccent? That’s a case where ThemeOverlay.AppCompat makes sense. First, add a theme (say, to a themes.xml file in your values folder):
<style “CustomAccentOverlay” parent=”ThemeOverlay.AppCompat”>
Then apply it to your View by adding android:theme=”CustomAccentOverlay”. This can be used to override any attribute, allowing you to customize things at a View level where appropriate, giving you one more tool you may need to #BuildBetterApps