Android – how to create a button with shadow

androidandroid-drawablebutton

How to create such button with shadow:

enter image description here

I don't know how to modify this button drawable:

<?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item >
    <shape android:shape="rectangle">
        <gradient android:angle="90" android:startColor="#0F9D58" android:endColor="#0F9D58" />
        <stroke android:width="1dp" android:color="#BABABA" />
        <corners android:radius="4dp" />
        <padding android:bottom="10dp"  android:top="10dp" android:left="20dp" android:right="20dp" />
    </shape>
</item>

Thanks!

UPDATE. Finally , the code should be as follows:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <layer-list>
        <item android:left="5dp" android:right="5dp" android:top="5dp">
            <shape>
                <corners android:radius="3dp" />
                <solid android:color="#0F4858" />
            </shape>
        </item>
        <item android:bottom="2dp" android:left="0dp" android:right="0dp">
            <shape>
                <gradient android:angle="270"
                          android:endColor="#0F9D58" android:startColor="#0F9D58" />
                <padding android:bottom="10dp" android:left="10dp"
                         android:right="10dp" android:top="10dp" />
            </shape>
        </item>
    </layer-list>
</item>
</selector>

Best Solution

Read this thread

Basically, you need create a xml for your custom button, like:

button_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <layer-list>
        <item android:right="5dp" android:top="5dp">
            <shape>
                <corners android:radius="3dp" />
                <solid android:color="#D6D6D6" />
            </shape>
        </item>
        <item android:bottom="2dp" android:left="2dp">
            <shape>
                <gradient android:angle="270" 
                    android:endColor="#E2E2E2" android:startColor="#BABABA" />
                <stroke android:width="1dp" android:color="#BABABA" />
                <corners android:radius="4dp" />
                <padding android:bottom="10dp" android:left="10dp" 
                    android:right="10dp" android:top="10dp" />
            </shape>
        </item>
    </layer-list>
</item>

And now, you can use it, doing reference to the file with:

<Button
   android:background="@drawable/button_selector"
   ...
   ..
/>