删除按钮中的阴影

时间:2015-01-15 15:05:18

标签: android

我创建了一个按钮,将背景设置为@null,但阴影仍在那里。

如何删除阴影?

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

2 个答案:

答案 0 :(得分:1)

试试:

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

BTW:你的背景为null对我没有影子

答案 1 :(得分:0)

您必须通过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"
/>

和drawables文件夹中的背景

抽拉/ 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

相关问题