The rules are pretty clear:
- When you start Android , the style with the best match is selected
If the selected style is a child, Android combines its elements with the parent best-match style.
If you provide your mutable element via a link, simply define its value to match the selected api version.
<style name="SomeStyle">
<item name="someColor">@color/some_color</item>
</style>
You can have some_color.xmlin the folder color-v21for API 21 and a common version of this file in the folder colorfor all other api levels.
Example:
Do you want to have the following style for non-v21 API
<style name="FinalStyle">
<item name="commonText">It\ a common text</item>
<item name="specificDrawable">@drawable/icon</item>
<item name="specificColor">@color/primary_color</item>
<item name="specificText">non-v21</item>
</style>
And the following style for API v21
<style name="FinalStyle">
<item name="commonText">It\ a common text</item>
<item name="specificDrawable">@drawable/icon</item>
<item name="specificColor">@color/secondary_color</item>
<item name="specificText">v21</item>
</style>
Specific parameters differ between API v21 / non-v21, common parameters are common.
How to do it?
res/values/styles.xml
<style name="BaseStyle">
<item name="commonText">It\ a common text</item>
<item name="specificDrawable">@drawable/icon</item>
</style>
<style name="FinalStyle" parent="BaseStyle">
<item name="specificColor">@color/primary_color</item>
<item name="specificText">non-v21</item>
</style>
res/values-v21/styles.xml
<style name="FinalStyle" parent="BaseStyle">
<item name="specificColor">@color/secondary_color</item>
<item name="specificText">v21</item>
</style>
res/drawable/icon.png
Common icon
res/drawable-v21/icon.png
v21 icon
Android FinalStyle v21, FinalStyle res/values-v21 BaseStyle. , Android @drawable/icon.