Resources.getDrawable(int) has been deprecated starting from API Level 22 , so what to use instead ?
There are three alternatives :
- Android 5.0 (API Level 21) added a method to obtain drawable in Context :
Drawable getDrawable(int id)
which returns a drawable associated with a particular resource ID and styled for the current theme.
- In the support Library ContextCompat has :
Drawable getDrawable(Context context, int id)
which returns a drawable associated with the resource id and Starting in from 5.0 drawable will be styled with the Context's theme.
- In Resources class :
which returns a drawable associated with the resource id and styled for the passed in theme , if the theme is null it will return an unthemed drawable.