Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to remove the grey background from ImageButtons?

I have an ImageButton and I'd like to remove the ugly (IMHO) background that surrounds the Image. I could just add an ImageView, but they're very hard to get set perfectly in a Layout like the grey one pictured. [gravity "Center" doesn't make it go to the middle, just centers it Vertically.)

So any way to remove that?

enter image description here

like image 486
Cole Avatar asked Mar 02 '12 02:03

Cole


People also ask

How to remove button background in android?

To remove the standard button background image, define your own background image or set the background color to be transparent. Save the XML file in your project res/drawable/ folder and then reference it as a drawable for the source of your ImageButton (in the android:src attribute).

What is ImageButton in android?

An ImageButton is an AbsoluteLayout which enables you to specify the exact location of its children. This shows a button with an image (instead of text) that can be pressed or clicked by the user.

How to use an image as a button android?

In android, we can add an image to the button by using <ImageButton> attribute android:src in XML layout file or by using the setImageResource() method. In android, we can create ImageButton control in two ways either in the XML layout file or create it in the Activity file programmatically.


3 Answers

Just use android:background="#0000" (#0000 same with #00000000) or

ImageButton imageButton = new ImageButton(this);
imageButton.setBackgroundDrawable(null);
like image 76
Nguyen Minh Binh Avatar answered Oct 09 '22 07:10

Nguyen Minh Binh


The default background is not transparent.

So, just add the transparent color "#00000000" as you background, then you could solve it.

p.s. #00000000 is the transparent color

<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon" 
android:background="#00000000"
/>
like image 30
dong221 Avatar answered Oct 09 '22 08:10

dong221


You can keep the square box and just change its color like this:

android:backgroundTint="@color/colorPrimary"

works beautifully

like image 5
David A Avatar answered Oct 09 '22 06:10

David A