How do you obtain a Drawable object from a resource id in android package?

Blaskovicz picture Blaskovicz · Oct 19, 2011 · Viewed 154k times · Source

I need to get a Drawable object to display on an image button. Is there a way to use the code below (or something like it) to get an object from the android.R.drawable.* package?

for example if drawableId was android.R.drawable.ic_delete

mContext.getResources().getDrawable(drawableId)

Answer

Pete Houston picture Pete Houston · Oct 19, 2011
Drawable d = getResources().getDrawable(android.R.drawable.ic_dialog_email);
ImageView image = (ImageView)findViewById(R.id.image);
image.setImageDrawable(d);