ImageButton in Android with transparent background

﹥>﹥吖頭↗ 提交于 2019-12-20 09:35:41

问题


I have follow this post to make ImageButton in android

android image button

The image appears to the button but it has some background , my Image is a png image and I want the button to be transparent background

any one help please


回答1:


add this line to your ImageButton xml layout.

android:background="@null"



回答2:


Here's an alternative solution that worked for me:

android:background="@android:color/transparent"

As Sunny said, add it to the ImageButtons' XML layout




回答3:


In your code use this:

ImageButton btn = new ImageButton(this);
btn.setImageResource(R.drawable.btn_close);
btn.setBackgroundResource(0);



回答4:


I don't know if there is any method to do that, but you can paint completely transparent .png file and use method setBackGroundResource() or in XML using this : android:background




回答5:


By this way you can set transparent background to ImageButton:

<ImageButton android:id="@+id/imagebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/<imageresourcename>"
android:background="@null"></ImageButton>


来源:https://stackoverflow.com/questions/9195963/imagebutton-in-android-with-transparent-background

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