This is a follow up question to this question:
Update Android Support Library to 23.2.0 cause error: XmlPullParserException Binary XML file line #17
Event after trying the already provided answers, the app was crashing on some devices (mainly Samsung). So along with that, I tried loading vector drawables like this
Drawable drawable = AppCompatDrawableManager.get().getDrawable(context, R.drawable.resource_id);
This AppCompatDrawableManager
internally tries to fetch drawable with various methods:
Drawable getDrawable(@NonNull Context context, @DrawableRes int resId,
boolean failIfNotKnown) {
checkVectorDrawableSetup(context);
Drawable drawable = loadDrawableFromDelegates(context, resId);
if (drawable == null) {
drawable = createDrawableIfNeeded(context, resId);
}
if (drawable == null) {
drawable = ContextCompat.getDrawable(context, resId);
}
if (drawable != null) {
// Tint it if needed
drawable = tintDrawable(context, resId, failIfNotKnown, drawable);
}
if (drawable != null) {
// See if we need to 'fix' the drawable
DrawableUtils.fixDrawable(drawable);
}
return drawable;
}
Thus it works on all android versions and all devices (hopefully).
Note: Don't try to use Picasso(2.5.2)'s or Glide(3.7.0)'s method to load vector drawables. Because they internally use deprecated getDrawable(@DrawableRes int id)
method. Which will result in Resources.NotFoundException
on some devices.