30

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

Community
  • 1
  • 1
Amira Elsayed Ismail
  • 9,216
  • 30
  • 92
  • 175

5 Answers5

80

add this line to your ImageButton xml layout.

android:background="@null"
Sunny
  • 14,522
  • 15
  • 84
  • 129
12

Here's an alternative solution that worked for me:

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

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

mestrini
  • 141
  • 1
  • 6
1

In your code use this:

ImageButton btn = new ImageButton(this);
btn.setImageResource(R.drawable.btn_close);
btn.setBackgroundResource(0);
jlapoutre
  • 1,767
  • 18
  • 22
0

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

Ricardo Simmus
  • 334
  • 4
  • 19