Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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) 
like image 653
Blaskovicz Avatar asked Oct 19 '11 01:10

Blaskovicz


People also ask

What is drawable resource in android?

A drawable resource is a general concept for a graphic that can be drawn to the screen and which you can retrieve with APIs such as getDrawable(int) or apply to another XML resource with attributes such as android:drawable and android:icon . There are several different types of drawables: Bitmap File.


1 Answers

Drawable d = getResources().getDrawable(android.R.drawable.ic_dialog_email); ImageView image = (ImageView)findViewById(R.id.image); image.setImageDrawable(d); 
like image 104
Pete Houston Avatar answered Oct 12 '22 01:10

Pete Houston