Android getResources().getDrawable() deprecated API 22

You have some options to handle this deprecation the right (and future proof) way, depending on which kind of drawable you are loading:

A) drawables with theme attributes


You’ll obtain a styled Drawable as your Activity theme instructs.
This is probably what you need.

B) drawables without theme attributes

ResourcesCompat.getDrawable(getResources(),, null);

You’ll get your unstyled drawable the old way. Please note: ResourcesCompat.getDrawable() is not deprecated!

EXTRA) drawables with theme attributes from another theme

ResourcesCompat.getDrawable(getResources(),, anotherTheme);

Edit: see my blog post on the subject for a more complete explanation

You should use the following code from the support library instead:

ContextCompat.getDrawable(context, R.drawable.***)

Using this method is equivalent to calling:

    return resources.getDrawable(id, context.getTheme());
} else {
    return resources.getDrawable(id);

As of API 21, you should use the getDrawable(int, Theme) method instead of getDrawable(int), as it allows you to fetch a drawable object associated with a particular resource ID for the given screen density/theme. Calling the deprecated getDrawable(int) method is equivalent to calling getDrawable(int, null).

Replace this line :

with ResourcesCompat.getDrawable(getResources(), R.drawable.your_drawable, null)


ResourcesCompat is also deprecated now. But you can use this:

ContextCompat.getDrawable(this, R.drawable.your_drawable) (Here this is the context)

for more details follow this link: ContextCompat

Leave a Comment