Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a transparent Button?

I am trying to create a transparent Button. In details I set the background's button with an image and I would like to modify the transparency of the button in order to see the background layout's color.

like image 928
francedema Avatar asked May 05 '13 10:05

francedema


4 Answers

you can use setAlpha() method to your Button.

Usingbutton.setAlpha(0.0)from your java code, will make your button fully transparent.

Or you can also use it in your layout xml. Inside your <Button /> tag use the following attribute:

android:alpha="0"
like image 91
shaonAshraf Avatar answered Nov 02 '22 23:11

shaonAshraf


If you use

?android:attr/selectableItemBackground

you'll have a transparent background with Ripple Effect according to this article of android-developers

Here an example

<Button
    android:id="@+id/test"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Change Password"
    android:background="?android:attr/selectableItemBackground"
    android:textSize="12sp"
    android:gravity="left|center"/>
like image 42
Jorge Casariego Avatar answered Nov 03 '22 01:11

Jorge Casariego


You can use android:alpha="0.5" to set your button half-transparent (the value has to be a float, where 0.0 is invisible and 1.0 is opaque), but be aware that this only works from API Level 11 (Android 3.0) onwards.

Another option would be to make change the background image itself and make it transparent using a graphics program like Gimp or Fireworks.

like image 25
Ridcully Avatar answered Nov 03 '22 00:11

Ridcully


simply if you want to make button transparent you can use

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

or use #0000 four zero in has code.let it only be 4 otherwise it will be considered as black.

hope this helps

like image 45
karan Avatar answered Nov 03 '22 00:11

karan