4

I searched about the shadow button (shown below) but haven't found the desired result. I want same as shown in the image below.

enter image description here

I tried this also How to provide shadow to Button.

I also tried elevation and translation Z (z) android method for shadow but nothing helped. Please guide me through this. Thank you.

Community
  • 1
  • 1
Nabeel Hafeez
  • 105
  • 1
  • 2
  • 13

3 Answers3

2

Create your own xml file in drawable folder and set in your button background.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!--the shadow comes from here-->
    <item
        android:bottom="-6dp"
        android:drawable="@android:drawable/dialog_holo_light_frame"
        android:left="-6dp"
        android:right="-6dp"
        android:top="-6dp">

    </item>

    <item
        android:bottom="-6dp"
        android:left="-6dp"
        android:right="-6dp"
        android:top="-6dp">

        <shape android:shape="rectangle">
            <solid android:color="@color/transparent" />
        </shape>
    </item>
</layer-list>

Boken
  • 4,825
  • 10
  • 32
  • 42
Umesh
  • 86
  • 8
1

Quick Shadow Color Glow

Set your button's attributes to

android:background="@android:drawable/dialog_holo_light_frame"
android:backgroundTint="@color/cool"

The tint is for api 21+ but you can walk around this programmically using

button.getBackground().mutate().setColorFilter(parseColor(tintColor), PorterDuff.Mode.SRC_ATOP);
-1

use this code

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/your_btncolor" />
            <corners android:radius="5dp" />
        </shape>
    </item>
    <item
        android:bottom="-15dp"
        android:left="-5dp"
        android:right="-5dp">
        <shape android:shape="rectangle">
            <solid android:color="@color/your_btn_shadowcolor" />
            <corners android:radius="5dp" />
        </shape>
    </item>
</layer-list>
Boken
  • 4,825
  • 10
  • 32
  • 42
Mahesh Gawhane
  • 348
  • 3
  • 20