With new android API 22 getResources().getDrawable()
is now deprecated.
Now the best approach is to use only getDrawable()
.
What change?
With new android API 22 getResources().getDrawable()
is now deprecated.
Now the best approach is to use only getDrawable()
.
What change?
Edit: see my blog post on the subject for a more complete explanation
You should use the following code from the support library instead:
Using this method is equivalent to calling:
As of API 21, you should use the
getDrawable(int, Theme)
method instead ofgetDrawable(int)
, as it allows you to fetch a drawable object associated with a particular resource ID for the given screen density/theme. Calling the deprecatedgetDrawable(int)
method is equivalent to callinggetDrawable(int, null)
.Just an example of how I fixed the problem in an array to load a listView, hope it helps.
en api level 14
You can use
that's work for me
Replace this line :
getResources().getDrawable(R.drawable.your_drawable)
with
ResourcesCompat.getDrawable(getResources(), R.drawable.your_drawable, null)
EDIT
ResourcesCompat
is also deprecated now. But you can use this:ContextCompat.getDrawable(this, R.drawable.your_drawable)
(Herethis
is the context)for more details follow this link: ContextCompat
getResources().getDrawable()
was deprecated in API level 22. Now we must add the theme:getDrawable (int id, Resources.Theme theme) (Added in API level 21)
This is an example:
This is an example how to validate for later versions: