2015-01-15 135 views
0

我创建了一个按钮,将背景设置为@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" /> 
+0

你有活动定义的其他样式该按钮在添加?可能是一种风格添加了阴影?检查AndroidManifest.xml – peshkira

+0

我没有添加任何样式 –

+1

@null也适用于我。你在运行什么版本的Android? – peshkira

回答

1

试一下:

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

BTW:你的背景,空对我的作品没有阴影

+0

不要工作。 Maeby它是清单中的主题? –

+0

尝试在新的android项目中的代码,也许你是对的 –

+0

这很奇怪!在我的Eclipse Button中有阴影。当我发布到真正的手机 - 按钮没有影子... =/ –

0

您必须指定通过绘制背景。

<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" 
/> 

,并在绘图资源文件夹背景

绘制/ 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