支持库 VectorDrawable Resources$NotFoundException

2023-12-27

我正在使用设计支持库版本23.4.0。我已经启用了 gradle 标志:

defaultConfig {
    vectorDrawables.useSupportLibrary = true
}

我正在使用构建工具版本23.0.2,但我仍然得到Resources$NotFoundExceptionKitKat 或更低版本。

当我使用时它发生android:drawableLeft or imageView.setImageResource(R.drawable.drawable_image).

是的,我将其放在使用可绘制对象的每项活动中

static {
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}

这是支持库的错误吗?


我花了 3 件不同的事情才能让它工作起来支持库23.4.0:

  1. 将其添加到build.gradle

    defaultConfig {
        vectorDrawables.useSupportLibrary = true
    }
    
  2. 将以下内容添加到onCreate你的Application class

    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    

    (来自此链接的参考-“https://stackoverflow.com/a/45582033/10752962 https://stackoverflow.com/a/45582033/10752962")

    In API 小于 21,之前使用此行setContentView();

  3. 对于要在其中设置矢量可绘制替换的所有 XML 视图

    android:src
    

    with

    app:srcCompat
    

    并在代码中替换:

    imageView.setImageResource(...);
    

    with

    imageView.setImageDrawable(...);
    
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

支持库 VectorDrawable Resources$NotFoundException 的相关文章

随机推荐