ImageButton in Android with transparent background

筅森魡賤 提交于 2019-12-02 19:02:38

add this line to your ImageButton xml layout.

android:background="@null"

Here's an alternative solution that worked for me:

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

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

In your code use this:

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

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

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