Transparent background for button
Asked Answered
S

3

5

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 '').
Souvenir answered 26/9, 2015 at 19:57 Comment(2)
android:background="#AARRGGBB" where AA is your alpha channel. Set this to 00 to be transparent.Nardoo
Matt Clark +1 , android:background ="#00000000"Rodneyrodolfo
M
10

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

android:background="@android:color/transparent"
Mckinleymckinney answered 26/9, 2015 at 20:1 Comment(0)
P
19

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.

Pentalpha answered 26/9, 2015 at 20:2 Comment(2)
requires higher API versionSouvenir
Could you add an explanation and for example link to a documentation, please?Pardon
M
10

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

android:background="@android:color/transparent"
Mckinleymckinney answered 26/9, 2015 at 20:1 Comment(0)
B
3

You can use android:background="@null"

Blankbook answered 26/9, 2015 at 20:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.