Recently I am trying to add Vector Drawable
in my work. I am using glide to set my drawables. Here is my code :
Glide
.with(mContext)
.load(resDrawable)
.placeholder(placeHolderResDrawable)
.centerCrop()
.bitmapTransform(new CropCircleTransformation(MyLruBitmapPool.getInstance()))
.into(imgRoundedView);
Here I put vector drawable
to resDrawable
and placeHolderResDrawable
. It was working fine in Lolipop
device. But when I tested it in less than lolipop
than it crashed. When trying to put drawable
in placeholder
it gave Resources$NotFoundException
.
Here is the crash report:
android.content.res.Resources$NotFoundException: File res/drawable/default_round_profile.xml from drawable resource ID #0x7f02013d at android.content.res.Resources.loadDrawable(Resources.java:3451) at android.content.res.Resources.getDrawable(Resources.java:1894) at com.bumptech.glide.request.GenericRequest.getPlaceholderDrawable(GenericRequest.java:395) at com.bumptech.glide.request.GenericRequest.begin(GenericRequest.java:265) at com.bumptech.glide.manager.RequestTracker.runRequest(RequestTracker.java:36) at com.bumptech.glide.GenericRequestBuilder.into(GenericRequestBuilder.java:616) at com.bumptech.glide.GenericRequestBuilder.into(GenericRequestBuilder.java:652) at com.bumptech.glide.DrawableRequestBuilder.into(DrawableRequestBuilder.java:436)
Try to get the drawable using ContextCompat
and set it as placeholder:
ContextCompat.getDrawable(mContext, placeHolderResDrawable);
So it would be:
Glide.with(mContext)
.load(resDrawable)
.placeholder(ContextCompat.getDrawable(mContext, placeHolderResDrawable))
.centerCrop()
.bitmapTransform(new CropCircleTransformation(MyLruBitmapPool.getInstance()))
.into(imgRoundedView);
Update for Glide v4:
Glide.with(mContext)
.load(resDrawable)
.apply(new RequestOptions()
.placeholder(ContextCompat.getDrawable(mContext, placeHolderResDrawable))
.centerCrop()
.transform(new CropCircleTransformation(MyLruBitmapPool.getInstance())))
.into(imgRoundedView);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With