As you can see in image, I want shadow behind a Button
. I have created Button
with rounded corners. But problem is I can't generate a shadow behind that Button
. How can I achieve this?
In CSS, shadows on the boxes of elements are created using the box-shadow property (if you want to add a shadow to the text itself, you need text-shadow ). The box-shadow property takes a number of values: The offset on the x-axis. The offset on the y-axis.
Use this approach to get your desired look.
button_selector.xml :
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item> <layer-list> <item android:right="5dp" android:top="5dp"> <shape> <corners android:radius="3dp" /> <solid android:color="#D6D6D6" /> </shape> </item> <item android:bottom="2dp" android:left="2dp"> <shape> <gradient android:angle="270" android:endColor="#E2E2E2" android:startColor="#BABABA" /> <stroke android:width="1dp" android:color="#BABABA" /> <corners android:radius="4dp" /> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" /> </shape> </item> </layer-list> </item> </selector>
And in your xml layout:
<Button android:background="@drawable/button_selector" ... .. />
For android version 5.0 & above
try the Elevation for other views..
android:elevation="10dp"
For Buttons,
android:stateListAnimator="@anim/button_state_list_animator"
button_state_list_animator.xml - https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/anim/button_state_list_anim_material.xml
below 5.0 version,
For all views,
android:background="@android:drawable/dialog_holo_light_frame"
My output:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With