Tutorials Android getDrawable() deprecated API 22 Alternative

Published on May 30th, 2016 | by James

2

Android getDrawable() deprecated API 22 Alternative

There are several options to handle getDrawable() deprecation (the right and future proof way), depending on which kind of drawable is being loaded:

A) Drawables without theme attributes

For unstyled drawable the old way. This is probably what is needed.
Please note:   ResourcesCompat.getDrawable()  is not deprecated!

B) Drawables with theme attributes

For a styled Drawable as the Activity theme instructs.

C) Drawables with theme attributes from another theme

Explanation:

Android 21 (5.0 Lollipop) introduced some new theme attributes such as android:colorAccent that modify the appearance of drawables that hold references to those new theme attributes values.

The AppCompat library handles pre and post-Lollipop drawable styling for you.

If the deprecated getDrawable() method is used to obtain a drawable resource with theme attributes, A partially-styled drawable and a logcat warning will come as output. It can be seen in API 22 android.content.res.Resources source code:

Tags: , ,


About the Author

is a full time Web Developer & App Developer. He enjoys to make modern websites. He loves technologies and writes about these. Now he's working with a software developing firm. He would like to help people around the world acquiring knowledge through his writing.



2 Responses to Android getDrawable() deprecated API 22 Alternative

  1. Adil Hussain says:

    Good explanation. Thanks.

  2. Our site says:

    K58Xw7 whoah this blog is wonderful i love reading your articles. Keep up the good work! You know, many people are hunting around for this info, you could aid them greatly.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to Top ↑