How to remove ImageButton's standard background image?

前端 未结 10 1342
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-13 01:50

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 i

相关标签:
10条回答
  • 2020-12-13 01:52

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

    See also:
        Android Developers official guide on Buttons

    0 讨论(0)
  • 2020-12-13 01:52

    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))
    })
    
    0 讨论(0)
  • 2020-12-13 01:53
    myButton.setBackgroundResource(0);
    
    0 讨论(0)
  • 2020-12-13 01:54

    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.

    0 讨论(0)
  • 2020-12-13 02:00

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

    0 讨论(0)
  • 2020-12-13 02:07

    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);

    0 讨论(0)
提交回复
热议问题