【问题标题】:VectorDrawableCompat Resources$NotFoundException under older versions of Android旧版本Android下的VectorDrawableCompat Resources$NotFoundException
【发布时间】:2016-05-26 14:18:52
【问题描述】:

我正在切换到矢量绘图,即使在较旧的 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 来使用它们。

编辑:我应该提到我在库模块中执行此操作。

【问题讨论】:

  • 这可能是开发人员忘记添加到支持库中的内容。你可以向谷歌开发者提出问题。

标签: android android-support-library android-design-library android-vectordrawable


【解决方案1】:

您需要在build.gradle 文件的defaultConfig 块内添加此行:

vectorDrawables.useSupportLibrary = true

这将在运行时为低于 21 的 API 生成 png,并且您不会因为找不到它们而收到错误消息。

【讨论】:

    猜你喜欢
    • 2016-06-17
    • 2020-09-17
    • 1970-01-01
    • 2016-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多