Button with transparent background

Asked

Viewed 7,649 times

1

I am creating button in my application like this

final Button btCategoria = (Button) LayoutInflater.from(this).inflate(R.layout.button, null);
        btCategoria.setId((int) listenerCategoria.id);
        btCategoria.setText(listenerCategoria.nome+"("+getSize((int) listenerCategoria.id)+" fotos)");

Layout

<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:id="@+id/btCategoria" />

this way the button is with the background totally transparent, I wanted to know if there is some way to leave partially transparent, some way to control

1 answer

4


For XML, might be something like that:

android:background="#66000000"

Where 66 represents 40% of 255 and the rest is the solid colour, in this case black.

Or dynamically, after setting the solid color of your button:

btCategoria.getBackground().setAlpha(102);

Where this whole amount goes from 0 (fully transparent) to 255 (totally opaque).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.