Android 支持库 v4:22+ 在可绘制对象中的 attr/ 上崩溃 pre Lollipop

Android support library v4:22+ crashing pre Lollipop on attr/ in drawables

我在处理具有支持库属性的形状可绘制对象时遇到了奇怪的效果。我有以下代码,在 inflation.

期间每次都会崩溃
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
<size android:width="26dp" android:height="26dp"/>
<solid android:color="?attr/colorPrimary"/>

注意我使用了 ?attr/colorPrimary 作为颜色。如果我使用

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
<size android:width="26dp" android:height="26dp"/>
<solid android:color="@color/primary"/>

它工作正常,没有任何崩溃。问题仅出现在设备 运行 低于 5.0 的 Android 版本中。我正在使用以下支持库

compile 'com.android.support:support-v4:22.2.1'

有人找到发生这种情况的原因吗?这是支持库中的错误吗?

<solid android:color="?attr/colorPrimary"/> 指向 Android 代码中的私有颜色(不是 public),可能在某些 API.[=16= 中不存在] 虽然 <solid android:color="@color/primary"/> 将指向您项目中的一种颜色,但也许您的颜色名称 primary 仅在文件夹 values-v21 中,因此它只会在低于 5.0
的版本中崩溃 我认为你应该尝试使用这个: <solid android:color="@android:attr/colorPrimary"/> 以确保属性存在。
希望这有帮助。