values、values-v11 和 values-v14 文件夹上的样式和主题 [英] Styles and themes on values, values-v11 and values-v14 folders

查看:33
本文介绍了values、values-v11 和 values-v14 文件夹上的样式和主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发我的应用,以将其设计基于 Holo 主题.在全球范围内,我想做的是工作,但我对文件夹 valuesvalues-v11values-v14.

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.

所以我知道:

  • values 针对的是低于 11 的 API
  • values-v11 针对 11 到 13 之间的 API
  • values-v14 的目标是优于 13 的 API
  • values is targeting the API inferior to 11
  • values-v11 is targeting the API between 11 and 13
  • values-v14 is targeting the API superior to 13

起初我以为我必须为每个文件夹指定应用程序所需的所有样式,但后来我意识到一种继承系统已经到位.

At 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.

我的问题是我真的很困惑,并且不清楚如何在这 3 个文件夹之间进行这种继承.

My problem is that I am really confused and don't understand clearly how is working this inheritance between these 3 folders.

我进行了以下测试以查看手机上的行为(在 Android 4.0 上运行,因此应加载文件夹 values-v14):

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):

values 中,我有一个样式可以将文本颜色设置为蓝色:

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>

values-v11 中,我有一个样式可以将文本颜色设置为白色:

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>

values-v14 中,我有一个样式将文本颜色设置为红色:

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>

对于上面的第一种情况(每个文件夹具有不同的颜色),加载到我的文本上的颜色是红色,这意味着 values-v14 文件夹获得优先权.

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.

然后,如果我从 values-v14 文件夹中注释掉红色样式,文本将变为白色.这是否意味着即使设备面向 values-v14 文件夹,系统也会采用 values-v11 文件夹中的样式?我认为它可能会默认使用 values 文件夹而不是 values-v11.

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.

更一般地说,我的问题是,这 3 个文件夹是否作为父子文件夹工作?意思是:

More generally, my question is, are these 3 folders working as parent and child? Meaning that:

  • 如果设备在 API 版本 > 13 上运行,系统将加载 values-v14 然后是 values-v11 最后是 values.
  • 如果设备在 11 到 13 之间的 API 上运行,系统将加载 values-v11,然后加载 values.
  • 如果设备在 API 版本上运行
  • 11、系统只会加载values.
  • If the device is running on a API version > 13, the system will load values-v14 then values-v11 and finally values.
  • If the device is running on a API between 11 and 13, the system will load values-v11 and then values.
  • If the device is running on a API version < 11, the system will load only values.

如果确实如此,那么在父文件夹 values 中设置最大样式并仅在 v11 或 v14 中添加特定样式是否有意义?

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?

抱歉问了这么长的问题,我希望你说清楚,这个主题/样式系统在 Android 指南中只是简要描述,很难找到它是如何工作的信息...

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...

感谢您的帮助!

推荐答案

更一般地说,我的问题是,这 3 个文件夹是否作为父文件夹工作和孩子?

More generally, my question is, are these 3 folders working as parent and child?

这些文件夹使用最具体"的匹配系统,这意味着它将匹配最接近(较低)的 API 级别 values 文件夹:

Those folders work with a "most specific" matching system meaning it will match the closest(lower) API level values folder:

  • values-v14 目标 APIs >= 14(14 以下的版本根本不会选择它)
  • values-v11 如果 values-v14 存在,则目标 API 介于(包括)1113 之间否则 它将匹配以11 及以上开头的每个版本((对于11 以下的版本,它根本不会被选中))
  • values 是默认文件夹,它将是最后一个匹配的文件夹,涵盖其他 values-xx 文件夹未涵盖的其他 API 级别.您应该始终(与所有资源文件夹一样)在您的应用中拥有此文件夹
  • 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 app

如果它确实是这样工作的,那么这样做有意义吗?在父文件夹值中设置最大样式并仅添加v11 或 v14 中的特定内容?

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?

是的,这就是 Android 项目模板的构建方式(当您使用 Create new project... 时),它实际上告诉您使用 values-xx用于自定义的文件夹(不同的外观、使用较新的样式、属性):

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. -->

这篇关于values、values-v11 和 values-v14 文件夹上的样式和主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆