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:
YourImageButton.setBackgroundColor(Color.TRANSPARENT);
回答8:
myButton.setBackgroundResource(0);
回答9:
Use:
android:background="@null"
in your layout xml.
回答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))
})