我在 Android 应用程序中使用 SVG 作为 ImageView 的 src
,并使用 appSrc
属性来提供向后兼容性(SDK<21)。
但现在我尝试在我的 TextView 复合绘图(drawableXXX 属性)中使用它们,当我使用带有 KitKat 的设备时,我收到多个错误(与我使用 android:src
时遇到的错误相同) app:srcCompat
)。
Caused by: android.view.InflateException: Binary XML file line #261: Error inflating class
有人知道如何在复合绘图中使用它们吗?
最佳答案
到目前为止,您无法从 xml 属性添加 VectorDrawable,该功能仅限于 app:srcCompat
Android 开发人员 blog post
但是,您可以使用 VectorDrawableCompat.create(Resources, int, Theme)
以编程方式执行此操作,然后使用 TextView#setCompoundDrawables
将其作为复合可绘制对象添加到 TextView
参见:
developer.android.com/reference/android/support/graphics/drawable/VectorDrawableCompat.html
developer.android.com/reference/android/widget/TextView.html
关于android - 在 SDK<21 的CompoundDrawable 中使用 SVG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38107811/