Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to make the background of a button transparent?

Tags:

android

image

I have a button like so...

enter image description here

Sorry if it looks dark but as you can see, I have set the height and width to wrap content but the scaletype is not fitxy so there is still "button excess" if you will.

Is there any way to remove this?

like image 858
Ogen Avatar asked Jan 18 '26 14:01

Ogen


2 Answers

You can used ImageButton. Do it in your xml

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageButtonSettings"
    android:src="@drawable/tabbar_icon"
    android:background="@android:color/transparent"/>

or programmatically. 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 88
M D Avatar answered Jan 20 '26 06:01

M D


use an ImageButton and set the background of it to transparent like this : android:background="@android:color/transparent"

<ImageButton
        android:id="@+id/btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:src="@drawable/btn_login" />
like image 37
Houcine Avatar answered Jan 20 '26 06:01

Houcine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!