-1

I am currently learning android and wanted to make a button that has elevation effect in it. To be more precise I want elevation effect like the image below.

enter image description here

Can anyone help me on how to make this type of button in android studio?

ADM
  • 16,256
  • 11
  • 37
  • 69
REX
  • 13
  • 1
  • 2

2 Answers2

0

Add a XML file in drawable folder and name it a.xml:

 <?xml version="1.0" encoding="utf-8"?>
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Gray shadow. -->
   <item android:left="3dp" android:top="5dp">
      <shape>
         <solid android:color="@android:color/darker_gray" />
         <corners android:radius="15dp" />
      </shape>
   </item>
<!-- White foreground. -->
   <item android:bottom="5dp" android:right="3dp">
      <shape>
         <solid android:color="@android:color/white" />
         <corners android:radius="15dp" />
      </shape>
   </item>
</layer-list>

Add in your button:

<Button
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:ackground="@drawable/a.xml"
    android:text="Button" />

Output:

enter image description hereenter image description here

SamiunNafis
  • 101
  • 2
  • 5
0

You just need to add below line to Button tag in xml. It will add elevation as you wanted.

android:stateListAnimator="@null"
Priyanka Rajput
  • 1,387
  • 1
  • 4
  • 11