...- v21.xml的用途是什么? [英] What is the use of a ...-v21.xml?
问题描述
我正在为Android 4.0及更高版本开发一个应用程序.我刚刚更新到appcompat 22.2.0,但是在网上看到了所有这些对...- v21/v22.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!
推荐答案
我在values-v21文件夹中有这个theme.xml
I had this themes.xml in the values-v21 folder
res/values-v21/
目录包含当运行您的应用程序的设备处于API级别21或更高级别时将使用的资源.如果设备运行在旧版Android上,则res/values-v21/
目录将被忽略.
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?
它们用于为不同版本的Android提供不同版本的资源.
They are used to provide different versions of resources for different versions of Android.
对于themes.xml
文件,API Level 21+设备可能具有从Theme.Material
继承的主题.但是,该主题在较旧的设备上不存在.如果您在res/values/
中有一个试图引用Theme.Material
的主题,则您的应用将在那些较旧的设备上崩溃.因此,相反,您将一个主题放置在Theme.Holo
表示minSdkVersion
为11或更高版本),并覆盖在res/values-v21/
中改为使用Theme.Material
.
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
.
您可以在此示例应用中看到它,其中Theme.Apptheme
(我的应用程序的主题)从res/values/
中的Theme.Holo
继承,并且从res/values-v21/
中的Theme.Material
继承.在运行时使用哪个版本的Theme.Apptheme
取决于设备所使用的Android版本.
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.
这篇关于...- v21.xml的用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!