Typically, people create a null_image.xml resource file in a drawable folder and use this resource whenever they need to clear the background:
null_image.xml:
<?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 the background - just call:
ImageButton.setImageDrawable(R.drawable.null_image);
I don’t know why CSimth did not send a comment as an answer ... It was right, as for me
source
share