简体   繁体   English

如何在Android中使用多个xml“样式表”?

[英]How do I use multiple xml “style sheets” in Android?

I would like to use multiple xml style sheets in Android project. 我想在Android项目中使用多个xml样式表。

I have: 我有:

res/
  values/
    styles.xml
    some_other_styles_file.xml
    and_some_other_styles_file.xml
    ...

What is the proper way to: 正确的方法是:

1 - reference those files 1-引用这些文件

2 - reference individual styles from within different files 2-从不同文件中引用各个样式

And: 和:

3 - if using multiple xml style sheets, do style names need to be unique across files? 3-如果使用多个xml样式表,样式名称在文件中是否需要唯一? In other words could two files, each being used by the app, contain styles with the same name? 换句话说,两个文件(每个文件都由应用程序使用)是否可以包含具有相同名称的样式?

File names are just for your organization, they are all automatically compiled and referenced by R.style.<style_name> when in java , or by style = "@style/<style_name>" when in xml (such as layout files). 文件名仅适用于您的组织,在Java中时,它们都是由R.style.<style_name> 自动编译和引用的;在xml中 ,它们是由style = "@style/<style_name>" 自动引用的(例如布局文件)。 You can even mix types (eg have string resources in your styles.xml) 您甚至可以混合类型(例如,在styles.xml中具有字符串资源)

To create a set of styles, save an XML file in the res/values/ directory of your project. 要创建一组样式,请将XML文件保存在项目的res / values /目录中。 The name of the XML file is arbitrary, but it must use the .xml extension and be saved in the res/values/ folder. XML文件的名称是任意的,但是它必须使用.xml扩展名并保存在res / values /文件夹中。

The root node of the XML file must be <resources> . XML文件的根节点必须是<resources>

source 资源

  1. You reference them all the same way R.style.<style_name> 您可以使用R.style.<style_name>相同的方式引用它们R.style.<style_name>
  2. It does not matter which file the styles are defined (files are used for organization) 定义样式的文件无关紧要(文件用于组织)
  3. Yes the names must be unique. 是的,名称必须唯一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM