我在模块中的同一文件中定义了两个cardStyle属性,如下所示:
< declare-styleable name =“customAttr”> < attr name =“cardStyle”……
我找到了解决问题的方法! 解决方案是使用继承而不是引用另一种样式。
<style name="CardStyle" parent="CardView"> <item name="cardCornerRadius">8dp</item> <item name="cardElevation">6dp</item> <item name="android:layout_marginEnd">16dp</item> <item name="android:layout_marginStart">16dp</item> <item name="android:layout_marginTop">10dp</item> <item name="android:layout_marginBottom">10dp</item> </style> <style name="SettingsCardStyle" parent="CardStyle">
所以你想要从一个风格中覆盖一个样式:
资源限定符允许使用 app/src/flavor1/res 等等
app/src/flavor1/res
老答案(关于模块,而不是口味)
要在模块之间共享样式,我使用的是中间模式:
共同:
<style name="_CardStyle" parent="CardView"></style>
module1(取决于常见):
<style name="CardStyle" parent="_CardStyle"></style>
module2(取决于常见):
你现在可以使用了 CardStyle 在你的模块中。
CardStyle