Can I make the button background transparent?

I have a button like this ...

enter image description here

Sorry if it looks dark, but as you can see, I set the height and width to wrap the content, but the scan type is not fitxy, so if you do this, there will be an “excess button”.

Is there any way to remove this?

+3
source share
5 answers

use ImageButtonand set its transparent view for it as follows: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" />
+3
source

You can use 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. it's simple, only you have to set the background color as transparent

ImageButton btn=(ImageButton)findViewById(R.id.ImageButton01);
btn.setBackgroundColor(Color.TRANSPARENT);
+4
source

//, android:alpha xml

// -

android:alpha="0.5"
+3

use #0000(only four zeros, otherwise it will be considered black) is the color code for transparent. You can use it directly, but I recommend that you define the color in color.xml so you can enjoy the re-usefulness of the code.

+1
source

Add Button Tag

following attribute:
<button
android:background="@android:color/transparent"/>
0
source

All Articles