我有两种风格,称之为 A 和 B。是否可以:
将它们应用到同一个 UI 元素,或者
将它们组合成一个单一的风格(基本上只是为了让我 完成第 1 点)
我知道样式可以从父级继承,所以我可以做一些事情,比如制作一个从 A 继承的样式 C,并将样式 B 中的所有属性复制到样式 C 中。但这反而违背了我要做的事情for - 我已将样式分组为样式 A 和 B 以避免重复代码,而将属性复制到 C 中则完全破坏了这一点。
不支持继承多种样式。但是,您可以创建一个具有
A
和 B
中所有共同点的基本样式。然后继承它。
<style name="SuperTheme" parent="android:Theme">
<!--All the attributes that A and B will have in common. -->
</style>
<style name="A" parent="SuperTheme">
<!--Unique attributes only in A. -->
</style>
<style name="B" parent="SuperTheme">
<!--Unique attributes only in B. -->
</style>
我发现声明两个独立的样式,然后创建一个在名称中引用样式 A 和 B 的单个样式将允许您合并这两种样式。
例如
<style name="A"/>
<style name="B"/>
可以通过创建来合并:
<style name="A.B"/>