Remove image resource of ImageButton

corecase picture corecase · Aug 6, 2012 · Viewed 15.3k times · Source

I have a transparent ImageButton. When clicked, the ImageResource of the button is set to a drawable in my drawable-hdpi folder (basically an image is shown on top of the transparent ImageButton). I'm using the ImageButton.setImageResource() method in order to do that. My question is, how can I remove the image resource so that there is only a transparent image button again. Of course, I need to be able to do this in java, not XML. I tried the following which failed to work: ImageButton.setImageResource(null); I also looked around a bit and couldn't find an answer... Thanks in advance for any help.

EDIT: Thank you all for your answers.. Péter Varga's answer did exactly what I needed so that's what i'm going with.

Answer

ᆼᆺᆼ picture ᆼᆺᆼ · Aug 6, 2012

Try setting imageButton.setImageResource(android.R.color.transparent).