How to remove ImageButton's standard background image?

女生的网名这么多〃 提交于 2019-11-27 10:04:47

问题


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


回答1:


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




回答2:


ImageButton.setBackgroundResource(0)




回答3:


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"



回答4:


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




回答5:


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.




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




回答7:


Use:

android:background="@null"

in your layout xml.




回答8:


YourImageButton.setBackgroundColor(Color.TRANSPARENT);



回答9:


myButton.setBackgroundResource(0);



回答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))
})


来源:https://stackoverflow.com/questions/5457138/how-to-remove-imagebuttons-standard-background-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!