I am currently working on my app to base its design on the Holo theme. Globally what I want to do is working but I am a little confused about the way that are working the folders values
, values-v11
and values-v14
.
So I know that:
values
is targeting the API inferior to 11values-v11
is targeting the API between 11 and 13values-v14
is targeting the API superior to 13At first I thought I had to specify for every folder all the styles needed for the app but then I realized a kind of inheritance system was in place.
My problem is that I am really confused and don't understand clearly how is working this inheritance between these 3 folders.
I did the following test in order to see the behavior on my phone (running on Android 4.0, so the folder values-v14
should be the one loaded):
In values
I have a style to set in blue the text color:
<style name="TextMedium" parent="@android:style/TextAppearance.Medium">
<item name="android:textColor">@color/Blue</item>
In values-v11
I have a style to set in white the text color:
<style name="TextMedium" parent="@android:style/TextAppearance.Medium">
<item name="android:textColor">@color/White</item>
In values-v14
I have a style to set in red the text color:
<style name="TextMedium" parent="@android:style/TextAppearance.Medium">
<item name="android:textColor">@color/Red</item>
For the first case above (every folder with a different color), the color loaded on my text is red, meaning the values-v14
folder gets the priority.
Then if I comment out the red style from the values-v14
folder, the text becomes white. Does that mean that the system will take the style in the values-v11
folder even if the device is targeting the values-v14
folder? I thought it would maybe use the values
folder by default but not values-v11
.
More generally, my question is, are these 3 folders working as parent and child? Meaning that:
values-v14
then values-v11
and finally values
.values-v11
and then values
.values
.If it is indeed the way it is working, does it make sense then to setup the maximum of styles in the parent folder values
and add only specific ones in v11 or v14?
Sorry for the long question, I hope it is clear, this themes/styles system is only described briefly in the Android guide and it is difficult to find information on how it works...
Thanks for your help!
More generally, my question is, are these 3 folders working as parent and child?
Those folders work with a "most specific" matching system meaning it will match the closest(lower) API level values
folder:
values-v14
targets APIs >= 14
(it will not be selected at all for versions below 14
)values-v11
targets APIs between(and including) 11
and 13
if values-v14
is present otherwise it will match every version starting with 11
and above((it will not be selected at all for versions below 11
)) values
is the default folder and it will be the last to be matched, covering other APIs levels not covered by another values-xx
folder. You should always(as with all resources folders) have this folder in your appIf it is indeed the way it is working, does it make sense then to setup the maximum of styles in the parent folder values and add only specific ones in v11 or v14?
Yes, this is how the Android project template is built(when you use Create new project...
), it actually tells you to use the values-xx
folders for customization(different look, use of newer styles, attributes):
<!-- in the styles.xml from the v-14 values folder: -->
<!-- API 14 theme customizations can go here. -->
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With