Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
173 views
in Technique[技术] by (71.8m points)

android - What is the use of a ...-v21.xml?

I am developing an app for android version 4.0 and up. I just updated to appcompat 22.2.0 but I am seeing all these references to ...-v21 / v22.xml's on the web. What are they used for? Do they make a difference? Thanks in advance!

question from:https://stackoverflow.com/questions/31303777/what-is-the-use-of-a-v21-xml

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I had this themes.xml in the values-v21 folder

A res/values-v21/ directory contains resources that will be used when the device that is running your app is on API Level 21 or higher. If the device is running on an older version of Android, the res/values-v21/ directory will be ignored.

What are they used for? Do they make a difference?

They are used to provide different versions of resources for different versions of Android.

In the case of a themes.xml file, an API Level 21+ device could have a theme that inherits from Theme.Material. However, that theme does not exist on older devices. If you have a theme in res/values/ that tries to refer to Theme.Material, your app will crash on those older devices. So, instead, you put a theme in res/values/ that will work on all devices that you are supporting (e.g., Theme.Holo for a minSdkVersion of 11 or higher), and override that theme in res/values-v21/ to instead use Theme.Material.

You can see that in this sample app, where Theme.Apptheme (my app's theme) inherits from Theme.Holo in res/values/ and inherits from Theme.Material in res/values-v21/. Which version of Theme.Apptheme is used at runtime depends on what version of Android the device has.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...