Alexander Vasilchuk
Alexander Vasilchuk

Reputation: 155

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 '').

Upvotes: 5

Views: 11025

Answers (3)

Ivan
Ivan

Reputation: 978

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.

Upvotes: 19

wasyl
wasyl

Reputation: 3506

You can use android:background="@null"

Upvotes: 3

mohax
mohax

Reputation: 4585

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

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

Upvotes: 10

Related Questions