How to create a button with a shadow

How to create a button like this with a shadow:

enter image description here

I don't know how to change this button:

<?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>

      

Thank!

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>

      

+3


source to share


1 answer


Read this thread

Basically you need to create 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 by linking to the file with:

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

      

+2


source







All Articles