How to remove ImageButton's standard background image?

AndroidImagebutton

Android Problem Overview


In ImageButton I want to remove the standard button background image. In http://developer.android.com it is said, that one must define his\her own background image or set the background color to be transparent. I tried to set a black background, but it didn't make any effect...

Android Solutions


Solution 1 - Android

You can use android:background="@null" for your ImageButton.

See also:
    Android Developers official guide on Buttons

Solution 2 - Android

The best choice is not set a transparent background to your ImageButton.

Give to your user a feedback when the button is tapped.

android:background="?attr/selectableItemBackgroundBorderless"

Solution 3 - Android

ImageButton.setBackgroundResource(0)

Solution 4 - Android

use the following property in your in the xml of ImageButton:

android:background="@drawable/icon"

where icon is the name of the image kept in your drawable.

Solution 5 - Android

No, it has to be transparent, not black. Try color: #00FFFFFF

Solution 6 - Android

Dot't use button.setBackgroundResource(0); on some devices you will get:

> android.content.res.Resources$NotFoundException: Resource ID #0x0

Better use button.setBackgroundColor(Color.TRANSPARENT);

Solution 7 - Android

Use:

android:background="@null"

in your layout xml.

Solution 8 - Android

YourImageButton.setBackgroundColor(Color.TRANSPARENT);

Solution 9 - Android

myButton.setBackgroundResource(0);

Solution 10 - Android

Using Kotlin, you can do this:

val myImageButton = ImageButton(context).apply({
    background = null

    // and if you need to add drawable, simply use:

    setImageDrawable(ContextCompat.getDrawable(context, 
                         R.drawable.ic_save_black_24px))
})

Solution 11 - Android

In the latest android version, the background image doesn't remove even when you set android:background="@null".

Setting android:minHeight="0dp" works for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionlomzaView Question on Stackoverflow
Solution 1 - AndroidMudassirView Answer on Stackoverflow
Solution 2 - AndroidFilipe BritoView Answer on Stackoverflow
Solution 3 - AndroidPeterView Answer on Stackoverflow
Solution 4 - AndroidDinesh SharmaView Answer on Stackoverflow
Solution 5 - AndroidZsombor Erdődy-NagyView Answer on Stackoverflow
Solution 6 - AndroidSpyZipView Answer on Stackoverflow
Solution 7 - AndroiddigitaldaemonView Answer on Stackoverflow
Solution 8 - AndroidAlBeebeView Answer on Stackoverflow
Solution 9 - AndroidLeoView Answer on Stackoverflow
Solution 10 - AndroidHasan A YousefView Answer on Stackoverflow
Solution 11 - AndroidNeelaView Answer on Stackoverflow