我已经编写了一个带有自定义属性的自定义复合 View 。自定义属性之一是可绘制对象,我希望使用的文件是矢量可绘制对象。
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomView, 0, 0)
val iconDrawable = typedArray.getDrawable(R.styleable.CustomView_icon_drawable)
我不断收到 XmlPullParserException:二进制 XML 文件行 #1:无效的可绘制标签向量
这是为什么?
最佳答案
已解决。
我需要执行以下操作:
val drawableResId = typedArray.getResourceId(R.styleable.CustomView_icon_drawable, -1);
val drawable = AppCompatResources.getDrawable(getContext(), drawableResId)
关于android - 当drawable 资源是Vector Drawable 时,如何通过TypedArray 获取Drawable 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42863198/