I'm a bit confused with these two APIs.
ResourcesCompat.getDrawable(Resources res, int id, Resources.Theme theme)
Return a drawable object associated with a particular resource ID and styled for the specified theme. Various types of objects will be returned depending on the underlying resource -- for example, a solid color, PNG image, scalable image, etc.
Prior to API level 21, the theme will not be applied and this method simply calls through to getDrawable(int).
AppCompatResources.getDrawable(Context context, int resId)
Return a drawable object associated with a particular resource ID.
This method supports inflation of vector and animated-vector resources on devices where platform support is not available.
Here is my understand after some test
ContextCompat.getDrawable(@NonNull Context context, @DrawableRes int resId)
ResourcesCompat.getDrawable(@NonNull Resources res, @DrawableRes int id, @Nullable Theme theme)
AppCompatResources.getDrawable(@NonNull Context context, @DrawableRes int resId)
VectorDrawableCompat.create(@NonNull Resources res, @DrawableRes int resId, @Nullable Theme theme
The first thing see is VectorDrawableCompat
and ResourcesCompat
can specific theme
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
in onCreated
of Application class
1) For vector image
API >= 21
ContextCompat
work wellResourcesCompat
work wellAppCompatResources
work wellVectorDrawableCompat
work wellAPI < 21
ContextCompat
crashResourcesCompat
crashAppCompatResources
work wellVectorDrawableCompat
work well2) For normal image
ContextCompat
work wellResourcesCompat
work wellAppCompatResources
work wellVectorDrawableCompat
crashAppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
in onCreated
of Application class
1) For vector image
ContextCompat
work wellResourcesCompat
work wellAppCompatResources
work wellVectorDrawableCompat
work well2) For normal image
ContextCompat
work wellResourcesCompat
work wellAppCompatResources
work wellVectorDrawableCompat
crash