A_user A_user - 3 months ago 19
Android Question

How to create Drawable from resource

I have a image

res/drawable/test.png
(R.drawable.test).

I want to pass this image to a function which accepts
Drawable
.

(e.g. mButton.setCompoundDrawables())

So how to convert a image resource to an
Drawable
?

Answer

Your Activity should have the method getResources. Do:

Drawable myIcon = getResources().getDrawable( R.drawable.icon );