Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
339 views
in Technique[技术] by (71.8m points)

android - Support library VectorDrawable Resources$NotFoundException

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

defaultConfig {
    vectorDrawables.useSupportLibrary = true
}

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

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);
}

Is this a bug of the support library?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

  1. Add this to build.gradle

    defaultConfig {
        vectorDrawables.useSupportLibrary = true
    }
    
  2. Add the following to onCreate of your Application class

    AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
    

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

    In API less then 21,use this line before setContentView();

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

    android:src
    

    with

    app:srcCompat
    

    and in the code replace this:

    imageView.setImageResource(...);
    

    with

    imageView.setImageDrawable(...);
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...