Search code examples
androidresourcesdrawableandroid-context

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


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)

Solution

  • Drawable d = getResources().getDrawable(android.R.drawable.ic_dialog_email);
    ImageView image = (ImageView)findViewById(R.id.image);
    image.setImageDrawable(d);