我想在 Android 项目中使用多个 xml 样式表。
我有:
res/
values/
styles.xml
some_other_styles_file.xml
and_some_other_styles_file.xml
...
什么是正确的方法:
1 - 引用那些文件
2 - 引用不同文件中的个别样式
并且:
3 - 如果使用多个 xml 样式表,样式名称是否需要在文件中是唯一的?换句话说,应用程序使用的两个文件是否可以包含同名样式?
最佳答案
文件名仅适用于您的组织,它们都是自动编译并由R.style.<style_name>
引用的在 java 中,或通过 style = "@style/<style_name>"
在 xml 中(例如布局文件)。您甚至可以混合类型(例如,在您的 styles.xml 中包含字符串资源)
To create a set of styles, save an XML file in the res/values/ directory of your project. The name of the XML file is arbitrary, but it must use the .xml extension and be saved in the res/values/ folder.
The root node of the XML file must be
<resources>
.
- 您以相同的方式引用它们
R.style.<style_name>
- 样式定义在哪个文件中并不重要(文件用于组织)
- 是的,名称必须是唯一的。
关于android - 如何在 Android 中使用多个 xml "style sheets"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37191584/