我正在切换到矢量绘图,即使在较旧的Android版本上也能很好地工作。我的应用针对4+。我将其中一个通知切换为矢量图像,为此我必须以编程方式使用VectorDrawableCompat
。突然之间我得到了该通知的异常,因为它无法找到该资源。
这是一个例外:
Fatal Exception: android.content.res.Resources$NotFoundException: File res/drawable-hdpi-v4/vector_name.png from xml type xml resource ID #0x7f0201d5
at android.content.res.Resources.loadXmlResourceParser(Resources.java:3733)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:3680)
at android.content.res.Resources.getXml(Resources.java:2215)
at android.support.graphics.drawable.VectorDrawableCompat.create(VectorDrawableCompat.java:408)
这是我正在运行的代码:
VectorDrawableCompat vector = VectorDrawableCompat.create(getResources(), R.drawable.vector_name, null);
我的gradle文件有这一行vectorDrawables.useSupportLibrary = true
,就像我说的那样,所有其他向量都运行正常,但我主要是使用AppCompatImageView
来使用它们。
答案 0 :(得分:0)
您需要在defaultConfig
文件的build.gradle
块中添加此行:
vectorDrawables.useSupportLibrary = true
这将在运行时生成低于21的API的png,并且由于找不到它们而您不会收到错误。