【发布时间】:2017-08-09 08:18:38
【问题描述】:
我编写了一个带有自定义属性的自定义复合视图。其中一个自定义属性是 drawable,而我希望使用的文件是 Vector Drawable。
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomView, 0, 0)
val iconDrawable = typedArray.getDrawable(R.styleable.CustomView_icon_drawable)
我不断收到 XmlPullParserException: Binary XML file line #1: invalid drawable tag vector
这是为什么?
【问题讨论】:
-
你的drawable正确吗? Android 不支持 svg,但支持矢量绘图。这些有点不同。
-
是的 - 我编辑这个说 Vector Drawable 而不是 SVG
-
也许尝试使用
typedArray.getResourceId(..)获取drawable resourceId,然后使用ContextCompat.getDrawable(Context context, @DrawableRes int id)创建一个Drawable实例? -
您运行的 API 级别是什么?
-
我的最小值是 16,但我设置了 vectorDrawables.useSupportLibrary = true 设置。此外,我的父活动正在扩展 AppCompatActivity
标签: android android-vectordrawable