我遇到了与VectorDrawables的新向后兼容性问题.在支持库中,23.2是一个新功能,用于向后兼容所生成的Android VectorDrawables.
我有一个ImageView,它是一个SelectorDrawable分配给.这个Drawable拥有几个VectorDrawables所以我认为我应该使用app:srcCompat来兼容.但它在我的Galaxy S2上使用android 4.1.2不起作用.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_gps_fixed_24dp"android:state_activated="true" android:state_selected="true"></item>
<item android:drawable="@drawable/ic_gps_not_fixed_24dp" android:state_activated="true" android:state_selected="false"></item>
<item android:drawable="@drawable/ic_gps_not_fixed_24dp" android:state_activated="false" android:state_selected="true"></item>
<item android:drawable="@drawable/ic_gps_off_24dp" android:state_activated="false" android:state_selected="false"></item>
<item android:drawable="@drawable/ic_gps_not_fixed_24dp"></item>
</selector>
Run Code Online (Sandbox Code Playgroud)
所有drawables都是vector xml文件.
当使用此SelectorDrawable与srcCompat时,我收到此错误:
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_gps_fixed_24dp.xml from drawable resource ID #0x7f0201c1
at android.content.res.Resources.loadDrawable(Resources.java:1951)
at android.content.res.Resources.getDrawable(Resources.java:672)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:881).xml from drawable resource ID #0x7f0201c1
Run Code Online (Sandbox Code Playgroud)
使用android:src更糟糕.
如果我使用app:srcCompat中的一个矢量drawable,一切正常.所以我猜这是SelectorDrawable和兼容性的问题.
有没有人有同样的问题,并找到了解决方案,或者目前无法在Android 5之前的SelectorDrawables中使用VectorDrawables?
简要说明:
android vector android-appcompat android-support-library android-vectordrawable
随着新的Android支持更新,矢量drawables获得向后兼容性.我有一个带有各种路径的矢量图像.我希望通过单击按钮或基于输入值以编程方式更改路径的颜色.是否可以访问矢量路径的name参数?然后改变颜色.