'How to remove ImageButton's standard background image?

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...



Solution 1:[1]

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

See also:
    Android Developers official guide on Buttons

Solution 2:[2]

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:[3]

ImageButton.setBackgroundResource(0)

Solution 4:[4]

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:[5]

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

Solution 6:[6]

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:[7]

Use:

android:background="@null"

in your layout xml.

Solution 8:[8]

YourImageButton.setBackgroundColor(Color.TRANSPARENT);

Solution 9:[9]

myButton.setBackgroundResource(0);

Solution 10:[10]

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:[11]

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.