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?
To complement some of the answers here: backward-compatible support for VectorDrawables comes with a price and doesn't work in all cases.
In which cases does it work? I've made this diagram to help (valid for Support Library 23.4.0 to at least 25.1.0).
Support for vector drawables in places like
android:drawableLeft
was disabled in support library 23.3. It was announced on Google+:Links to issues:
However, if you can live with those issues, in 23.4 you can re-enable this functionality using AppCompatDelegate.setCompatVectorFromResourcesEnabled().
If you're curious how this works, the best person to learn from is Chris Banes, who authored this functionality. He explains in detail on his blog.
Try using:
You don't have to add
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
this way.Just inflate your vector drawables using VectorDrawableCompat and you're all set.
use this in app.gradle
Then use
AppCompatDrawableManager
to setDrawable and getDrawable. Works for meSorry for being late to the party but this answer may help users who want to enable the flag AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); for all activities.
1. Create a class which extends to Application (android.app.Application)
2. Head over to Manifest.xml and add the following line to your tag
3. Add the following code above onCreate in MyApplicationClass.java
Complete code for MyApplicationClass.java
change
to
if you want to use vectordrawable in xml, use this: