【发布时间】:2017-06-27 11:19:11
【问题描述】:
我有这个可绘制的 shape.xml,看起来没什么特别的:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="4dp"/>
<solid android:color="?colorPrimary"/>
</shape>
当我在 api 21 以下运行时它崩溃了,因为我认为它不支持使用
“?colorPrimary”。
用户可以正确选择不同的主题,那么我可以使用什么来代替下面 api 21 上的“?colorPrimary”?
如果我这样设置:
<solid android:color="@color/colorPrimary" />
然后我将为我的所有主题设置相同的颜色,这是不可取的。
在我的 styles.xml 中,我有 10 个不同的主题可供用户选择。
我知道我必须将 drawable shape.xml 移动到 drawable-v21 文件夹中,但是我应该如何更改默认 drawable 文件夹中相同的 shape.xml 以提供相同的功能?
【问题讨论】:
-
你为什么不试试这个——android:textColor="@color/colorPrimary"
-
此 shape.xml 用作 ListView 项的背景。在我的蓝色主题中,背景是蓝色的,在我的红色主题中,B 被读取