I have an image res/drawable/test.png
(R.drawable.test).
I want to pass this image to a function which accepts Drawable
, e.g. mButton.set
You must get it via compatible way, others are deprecated:
Drawable drawable = ResourcesCompat.getDrawable(context.getResources(), R.drawable.my_drawable, null);
This code is deprecated:
Drawable drawable = getResources().getDrawable( R.drawable.icon );
Use this instead:
Drawable drawable = ContextCompat.getDrawable(getApplicationContext(),R.drawable.icon);