Android drawable xml无法转换为API 10的颜色异常

前端之家收集整理的这篇文章主要介绍了Android drawable xml无法转换为API 10的颜色异常前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的应用程序中,我定义了我在自定义主题中设置的颜色属性

RES /值/ attrs.xml

@H_301_4@<resources> <attr name="bbColorPrimary" format="color|reference" /> </resources>

RES /值/ colors.xml

@H_301_4@<resources> <color name="white">#ffffff</color> </resources>

RES /值/ style.xml

@H_301_4@<style name="MyStyle" parent="@style/Theme.AppCompat.NoActionBar"> <item name="bbColorPrimary">@color/white</item> </style>

RES /抽拉/ background.xml

@H_301_4@<selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_pressed="true"> <shape> <solid android:color="?attr/bbColorPrimary" /> </shape> </item> <item> <shape> <solid android:color="@color/transparent" /> </shape> </item> </selector>

res / drawable / background.xml被设置为某个按钮的背景.应用程序在使res / drawable / background.xml文件膨胀时崩溃,但有以下异常:

@H_301_4@... Caused by: java.lang.UnsupportedOperationException: Can't convert to color: type=0x2 at android.content.res.TypedArray.getColor(TypedArray.java:326) at android.graphics.drawable.GradientDrawable.inflate(GradientDrawable.java:748) at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787) at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:172) ....

它适用于高于10的API级别.如果我删除了?attr / bbColorPrimary它工作正常,尽管在其他资源文件中设置了许多其他?attr / ..调用.我没有使用任何特定于版本的资源文件夹.

我在这做错了什么?

解决方法

我在SO上找到了答案,提到了?attr / ..在xml drawables中不受支持.见: https://stackoverflow.com/a/13471695/169748

显然,至少对于API< = 10来说这是真的.

猜你在找的Android相关文章