Search code examples
androidandroid-studiodropshadow

How to make a drop shadow on a custom shape


I want something like this: I want something like this:

I have the shape

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item >
    <shape android:shape="rectangle"  >
        <solid android:color="@color/white"/>
        <corners android:radius="15dip" />
        <stroke android:width="1dip" android:color="@color/shadow" />
    </shape>
</item>
</selector>

But my problem is the shadow, is there a way I can do this?


Solution

  • Use CardView to create shadow view in android

    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardBackgroundColor="@android:color/white"
        android:foreground="?android:attr/selectableItemBackground"
        card_view:cardElevation="3dp"
        card_view:cardCornerRadius="4dp">
    
    1. card_view:cardElevation="3dp" this is for shadow
    2. card_view:cardCornerRadius="4dp" this is for corner radius