回答

27

您可以使用簡單的查看和背景繪製自己的影子正上方的底欄:

<View 
    android:layout_width="match_parent" 
    android:layout_height="4dp" 
    android:layout_above="@id/bottom_bar" 
    android:background="@drawable/shadow"/> 

繪製/ shadow.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <gradient 
     android:startColor="#1F000000" 
     android:endColor="@android:color/transparent" 
     android:angle="90" /> 
</shape> 

而且,沒有兼容性問題,如果使用這種方法。

+0

的最佳解決方案。謝謝。 – Ahsan

+0

適合與舊版Android兼容 –

2

您可以使用標高陰影添加到任何視圖

<TextView 
android:id="@+id/myview" 
... 
android:elevation="2dp" 

android:background="@drawable/myrect" /> 

參考this瞭解更多信息

+0

在我的項目中不起作用:「屬性」提升「僅用於API級別21和更高(當前最小值爲16)」,如果確實有效,則會使用該屬性。 –