Custom button design for round corners using layer list

127 Views Asked by At

I just wat to create a button as shown in the image. But I am not able to make the round edges at the top corners. How we can do that..please help.

enter image description here

<item>
    <shape android:shape="rectangle">
        <solid android:color="#A32CB386" />
        <corners android:radius="5dp"/>
    </shape>
</item>

<item android:bottom="5px">
    <shape android:shape="rectangle">

        <solid android:color="#36885B" />
    </shape>
</item>
2

There are 2 best solutions below

2
On

You can use something like:

  <com.google.android.material.button.MaterialButton
      android:background="@drawable/test"
      app:backgroundTint="@null"
      />

with:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="false">
        <layer-list>
            <item>
                <!-- bottom shadow -->
                <shape>
                    <solid android:color="#2CB386"/>
                    <corners android:radius="5dp"/>
                </shape>
            </item>
            <item
                android:bottom="10px"
                >
                <shape>
                    <solid android:color="#36885B"/>
                    <corners
                        android:radius="5dp"/>
                </shape>
            </item>
        </layer-list>
    </item>
    <item android:state_pressed="true">
        <layer-list>
            <!-- ....  -->
        </layer-list>
    </item>
</selector>

enter image description here

2
On

Your drawable file. Let's say bg_sign_in.xml

<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="5dp" />
                <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" />
                <corners android:radius="5dp" />
            </shape>
        </item>
    </layer-list>
</item>

Apply the following in your xml

android:background="@drawable/bg_sign_in"

Output:

enter image description here