Button with transparent background

1

I'm creating button in my application so

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 completely transparent, I would like to know if there is some way to make it partly transparent, some way to control

    
asked by anonymous 09.02.2015 / 22:08

1 answer

4

By XML , it might look something like this:

android:background="#66000000"

Where 66 stands for 40% of 255 and the rest is solid color, in this case black.

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

btCategoria.getBackground().setAlpha(102);

Where this integer value goes from 0 (fully transparent) to 255 (totally opaque).

    
09.02.2015 / 22:26