Resources.getDrawable(int) is deprecated Since Android 5.1

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 :
Resources.getDrawable(int, Theme)  

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.