0

I found here how to create a shadow for a button. Here's what I would like to do : enter image description here

And here's what I succeeded to do so far :

enter image description here

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <layer-list>
            <item android:right="10dp" android:top="10dp">
                <shape>
                    <corners android:radius="3dp" />
                    <solid android:color="#D6D6D6" />
                </shape>
            </item>
            <item android:bottom="2dp" android:left="2dp">
                <shape>
                    <solid android:color="@color/mainBlue"/>
                    <corners android:radius="12dp" />
                    <padding android:bottom="10dp" android:left="10dp"
                        android:right="10dp" android:top="10dp" />
                </shape>
            </item>
        </layer-list>
    </item>

</selector>

Obviously the shadow is completely different, and if you notice, it is kind of cutten in the bottom left corner and we don't see the radius. In my design software, I specified an angle, a distance, a spread and a size for the shadow. How may I control these parameters in XML so that I can faithfully reproduce the same shadow ?

EDIT : what I ended up doing is to export my design as a png file as I didn't find any way to reproduce the shadow with code :/

Community
  • 1
  • 1
user54517
  • 2,020
  • 5
  • 30
  • 47
  • 1
    the other thread and the answers are 6 to 9 _years_ old. today there are completely different things possible. have you tried the MaterialButton control? it produces shadows according to google's design guidelines. here's a complete documentation with all possible stylings and xml attributes: https://material.io/develop/android/components/buttons/ Class documentation here: https://developer.android.com/reference/com/google/android/material/button/MaterialButton – Grisgram Apr 02 '20 at 08:59
  • Yes I checked that. However the shadow that I want to apply to my button is slightly different than google's guidelines. I was looking for some parameters which would allow me to reproduce the same one as in my design file :/ – user54517 Apr 02 '20 at 09:11

1 Answers1

0

Just try adding elevation to the button:

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/button_bg"
    android:elevation="10dp"
    android:textColor="@color/white" />

Make sure that you give your button a background, otherwise it won't work.

UnBanned
  • 121
  • 11