Java tutorial
//package com.java2s; import android.content.Context; import android.graphics.drawable.Drawable; import android.os.Build; import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; public class Main { @Nullable @SuppressWarnings("deprecation") static Drawable getDrawable(@NonNull Context context, @DrawableRes int drawableId) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) return context.getDrawable(drawableId); //noinspection deprecation return context.getResources().getDrawable(drawableId); } }