在我的应用程序中,我定义了我在自定义主题中设置的颜色属性:
RES /值/ attrs.xml
<resources> <attr name="bbColorPrimary" format="color|reference" /> </resources>
RES /值/ colors.xml
<resources> <color name="white">#ffffff</color> </resources>
RES /值/ style.xml
<style name="MyStyle" parent="@style/Theme.AppCompat.NoActionBar"> <item name="bbColorPrimary">@color/white</item> </style>
RES /抽拉/ background.xml
<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文件膨胀时崩溃,但有以下异常:
... 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来说这是真的.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。