Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent background for button

I need to set transparent background for my button, but only background, not all button. I've tried:

android:background=""
android:background="null"

and background changed on transparent, but i've got an error:

Error: String types not allowed (at 'background' with value '').
like image 548
Alexander Vasilchuk Avatar asked Sep 26 '15 19:09

Alexander Vasilchuk


People also ask

How do I make the background of a button transparent?

Make the button's background color transparent by changing the opacity of the button's Background color setting, using the color picker slider. See the this article about the color picker. Then you can create a button border in the Border section.

How do I make a button background transparent in bootstrap?

The <button> tag is used to specify the button element in HTML, which gets executed on pressed. btn – On mentioning the btn property, specifies that its a bootstrap button. bg – Specifies the background color of the button. transparent – Makes the button transparent.

How do I make a button transparent in XML?

Now it's time to make transparent background of android button. If you want to make 20 % transparent just add 80 at the first of your hex color code like android:background="#80000000" , if you want to make only 80 % transparent button then add 20 at the first of your hex color code like above.

How do I make a semi transparent button?

To achieve this, use a color value which has an alpha channel—such as rgba. As with opacity , a value of 1 for the alpha channel value makes the color fully opaque. Therefore background-color: rgba(0,0,0,. 5); will set the background color to 50% opacity.


2 Answers

Material Ripple effect with transparent background some Info

    android:background="?android:attr/selectableItemBackground"

For example

<Button
    android:layout_marginTop="15dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="?android:attr/selectableItemBackground"
    android:text="@string/add"
    android:layout_marginBottom="10dp"
    android:textSize="18sp"
    android:textStyle="bold"
    android:textColor="@color/fab_dark"
    android:id="@+id/btnOkFood"
    android:layout_gravity="right" />

With appcompat v7 this is supported for API => 11. It's a little better than a transparent background only because give a feedback of touch.

like image 103
Ivan Avatar answered Sep 21 '22 12:09

Ivan


Type of this attribute value should be color, so use buildin attribute for transparent background with color value:

android:background="@android:color/transparent"
like image 29
mohax Avatar answered Sep 19 '22 12:09

mohax