2015-01-15 138 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