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.
How do I remove background from ImageButton? You can use android:background="@null" for your ImageButton. Save this answer.
<ImageView android:id="@+id/simpleImageView" android:layout_width="fill_parent" android:layout_height="wrap_content" /> 2. src: src is an attribute used to set a source file or you can say image in your imageview to make your layout attractive.
Normally, people create null_image.xml resource file in drawable folder and use this resource whenever they need to clear background:
null_image.xml content:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#0000" />
<size
android:width="1dp"
android:height="1dp" />
</shape>
And when you need to clear background - just call:
ImageButton.setImageDrawable(R.drawable.null_image);
Don't know why CSimth did not post his comment as an answer... It was correct as for me
Try setting imageButton.setImageResource(android.R.color.transparent)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With