How to create shadow drawable for button?

155 Views Asked by At

I have tried by use of 9-patch drawable as layer list and also used gradient but in both cases i can not get accurate result, how can we design shadow drawable?

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:left="@dimen/_10sdp"
        android:right="@dimen/_10sdp">
        <shape android:shape="rectangle">

            <corners
                android:bottomLeftRadius="@dimen/_4sdp"
                android:bottomRightRadius="@dimen/_4sdp"
                android:topLeftRadius="@dimen/_50sdp"
                android:topRightRadius="50sp"
                />

            <gradient
                android:angle="90"
                android:startColor="#0D4c4c4c"
                android:endColor="#0D4c4c4c"
                android:centerColor="#334c4c4c"
                android:type="linear" />

        </shape>

    </item>
    <item android:bottom="@dimen/_7sdp">
        <shape android:shape="rectangle">
            <solid android:color="#b9b9b9" />
        </shape>
    </item>
</layer-list>
3

There are 3 best solutions below

0
Sandeep Malik On

you can set this tag in your xml file: android:elevation="6dp"

1
Karan Khurana On
   <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="false">
        <layer-list>
            <!-- SHADOW -->
            <item>
                <shape>
                    <solid android:color="@color/red_400"/>


                </shape>
            </item>

            <item
                android:bottom="5px"
                >
                <shape>
                    <padding android:bottom="5dp"/>
                    <gradient
                        android:startColor="#1c4985"
                        android:endColor="#163969"
                        android:angle="270" />
                    <corners
                        android:radius="19dp"/>
                    <padding
                        android:left="10dp"
                        android:top="10dp"
                        android:right="5dp"
                        android:bottom="10dp"/>
                </shape>
            </item>
        </layer-list>
    </item>
</selector>

Try this

0
Hardik Talaviya On

Please try below drawable

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <shape android:shape="rectangle">
            <gradient
                android:angle="180"
                android:startColor="#0D4c4c4c"
                android:endColor="#0D4c4c4c"
                android:centerColor="#334c4c4c"
                android:type="linear" />

        </shape>

    </item>
    <item android:bottom="@dimen/_10sdp">
        <shape android:shape="rectangle">
            <solid android:color="#b9b9b9" />
        </shape>
    </item>
</layer-list>

I hope this can help you!

Thank You.