This question has already been answered:

In the Android SDK <21, for example, there is no way to color the status bar. Or, for example, it is necessary to use a certain attribute, retaining all those working on older SDKs. Well, let's take, for example, the same colorPrimaryDark to indicate the color of the statusbar.

res / values ​​/ styles.xml

 <resources> <style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar"> <item name="colorAccent">@color/colorAccent</item> <item name="colorPrimary">@color/colorPrimary</item> </style> </resources> 

res / values-v21 / styles.xml

 <resources> <style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar"> <item name="colorAccent">@color/colorAccent</item> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> </style> </resources> 

How can I not write colorAccent and colorPrimary in values-v21 / styles.xml?

In general, how to make style inheritance between styles.xml for different API Level?

Reported as a duplicate by YurySPb. android Oct 4 '17 at 4:09 pm

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    1 answer 1

    Is the problem relevant with the use of appcompat-v7 ? You can set the color for the status bar, it simply will not be applied on older devices.

    In general, the problem is solved as follows: add another file with styles, for example, styles_base.xml , where you can put the “basic” style, naming it, for example, AppThemeBase . Then in your styles.xml , which will be somewhat for different versions (as you have done now), add a style with the same name AppTheme , which will be inherited from AppThemeBase

    <style name="AppTheme" parent="@style/AppThemeBase">

    Thus, for example, you can set different attributes on different versions of the platform, while having a set of some common elements.