Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set transparent background for Image Button in code?

I can set ImageButton background transparent in layout.xml using:

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

How I can acomplish same thing using java code? Something like ib.setBackgroundColor(???);

like image 959
Peter Avatar asked Jan 17 '11 04:01

Peter


People also ask

How do you make a button background transparent?

CSS Code: In this section, we will design the button using CSS property. We will use the background-color: transparent; property to set the button with transparent look. Complete Code: In this section, we will combine the above two sections to create a transparent background button.

How to set image button background transparent in android studio?

setImageResource(int) method. 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).


2 Answers

This is the simple only you have to set background color as transparent

    ImageButton btn=(ImageButton)findViewById(R.id.ImageButton01);     btn.setBackgroundColor(Color.TRANSPARENT); 
like image 108
Parag Chauhan Avatar answered Sep 21 '22 11:09

Parag Chauhan


Do it in your xml

<ImageButton         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:id="@+id/imageButtonSettings"         android:layout_gravity="right|bottom"         android:src="@drawable/tabbar_settings_icon"         android:background="@android:color/transparent"/> 
like image 27
bsautner Avatar answered Sep 18 '22 11:09

bsautner