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?
We had the same issue. Vector drawables were not visible on Kitkat. I solved this issue by adding
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
to the onCreate method of Activities.Before that dont forget to add:
and call setImageResource for the view that you use the vector drawable. My view is ImageButton. I have Android SDK build tools version 23.0.3
Do not put your vectors in
drawable-anydpi
, old devices does not support thatput them in
drawable
I had a similar problem long ago, it did not work by setting
vectorDrawables.useSupportLibrary = true
only worked when I created the "mipmap" folder, and the code used
imageView.setImageResource (R.mipmap.drawable_image)
It has more Info here
It took 3 separate things for me to get this to work using support library 23.4.0:
Add this to build.gradle
Add the following to onCreate of your Application class
For all xml views in which you are setting a vector drawable replace
with
and in the code replace this:
with
Inflating Drawable's
`VectorDrawable`
and`AnimatedVectorDrawable`
in this support library can be inflated in this way:getDrawable()
methods:If inflating the Drawable in java code, it is recommended to always use
ResourcesCompat.getDrawable()
as this handles Lollipop fallback when applicable. This allows the system to cache Drawable ConstantState and hence is more efficient.The library has the following morph (bi-directional) animations :
As you can see, I produced the above image on my
API 16
phone:Look at the github README for
vector-compat
here: https://github.com/wnafee/vector-compatThis will fix your problem (down to
API 14
) if you merge it with your app module'sbuild.gradle
dependencies
(usually at the end of file):Use
AppCompatImageView
instead ofImageView
as said by Harish Gyanani in comments , it works fine with this for me.Official docs