You should use the android: prefixed attributes in the theme for android 5+, since the option without a prefix is ββintended only for parts that support the application, for versions <android 5.
So, you should have one values/styles.xml for pre-android 5 and one values-v21/styles.xml for android 5 +.
In v21 styles, you define your theme as follows:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:colorPrimary">@color/light_purple</item> <item name="android:colorPrimaryDark">@color/dark_purple</item> <item name="android:colorAccent">@color/dark_purple</item> </style>
As you now define the colorPrimary attribute once simply as colorPrimary for pre-Lollipop and once as android:colorPrimary for Lollipop devices, you can no longer directly use ?attr/colorPrimary . Instead, like the others mentioned earlier, you should define your own style for the toolbar, but for both options:
values ββ/ styles.xml:
<style name="Toolbar"> <item name="android:background">?attr/colorPrimary</item> </style>
values-V21 / styles.xml:
<style name="Toolbar"> <item name="android:background">?android:attr/colorPrimary</item> </style>
And use the style for your toolbar:
<android.support.v7.widget.Toolbar style="@style/Toolbar"
Thus, the background color and other styles can be set on all versions and can still be changed using colorPrimary , which is set in the theme.
source share