支持库VectorDrawable Resources $ NotFoundException [英] Support library VectorDrawable Resources$NotFoundException

查看:77
本文介绍了支持库VectorDrawable Resources $ NotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using Design Support Library version 23.4.0. I have enabled the gradle flag:

defaultConfig {
    vectorDrawables.useSupportLibrary = true
}

我正在使用版本工具 23.0.2 ,但是仍然可以在KitKat或更低版本上获得Resources$NotFoundException.

I am using build tools version 23.0.2, but still, I am getting Resources$NotFoundException on KitKat or lower.

当我使用android:drawableLeftimageView.setImageResource(R.drawable.drawable_image)时会发生这种情况.

It is occurring when I use android:drawableLeft or imageView.setImageResource(R.drawable.drawable_image).

是的,我在使用可绘制对象的每个活动中都使用

And yes, I am putting this on every activity where I am using drawables

static {
    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}

这是支持库的错误吗?

推荐答案

使用支持库23.4.0 ,我花了3步才使它生效:

It took 3 separate things for me to get this to work using support library 23.4.0:

  1. 将此添加到build.gradle

defaultConfig {
    vectorDrawables.useSupportLibrary = true
}

  • 将以下内容添加到Application类的 onCreate

    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    

    (从此链接的引用-" https://stackoverflow.com/a/45582033/10752962 " )

    (From the reference of this link - "https://stackoverflow.com/a/45582033/10752962")

    API小于21 中,在setContentView();

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

    For all XML views in which you are setting a vector drawable replace

    android:src
    

    使用

    app:srcCompat
    

    ,并在代码中替换为:

    imageView.setImageResource(...);
    

    使用

    imageView.setImageDrawable(...);
    

  • 这篇关于支持库VectorDrawable Resources $ NotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆