Remove shadow in Button

I created a button, set the background to @null, but shadow is still there.

How can I remove the shadow?

<Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAllCaps="false"
        android:background="@null"
        android:text="Random" />

Upvotes: 0

Views: 3486

Answers (2)

John Twigg
John Twigg

Reputation: 7571

You have to specify a background via a drawable.

<Button
    android:id="@+id/shadowless_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/background_button"
    android:text="Press Me"
/>

and a background in the drawables folder

drawable/background_button.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">

        <!-- view background color -->
        <solid android:color="@android:color/darker_gray"></solid>

        <!-- view border color and width -->
        <stroke android:width="1dp" android:color="@android:color/black"></stroke>

        <!-- If you want to add some padding -->
        <!-- Here is the corner radius -->
        <corners android:radius="4dp"></corners>

    </shape>
</item>
<item>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">

        <!-- view background color -->
        <solid android:color="@android:color/white"></solid>

        <!-- view border color and width -->
        <stroke android:width="1dp" android:color="@android:color/darker_gray"></stroke>

        <!-- If you want to add some padding -->
        <!-- Here is the corner radius -->
        <corners android:radius="4dp"></corners>

    </shape>
</item>
</selector>

enter image description here enter image description here

Upvotes: 0

Janusz Hain
Janusz Hain

Reputation: 617

Try that:

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

BTW: your background as null works for me without the shadow

Upvotes: 1

Related Questions