Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to provide shadow to Button

enter image description here

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?

like image 824
Chintan Rathod Avatar asked Mar 11 '13 07:03

Chintan Rathod


People also ask

How do you add shadow to elements in CSS3?

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.


2 Answers

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"    ...    .. /> 
like image 147
Festus Tamakloe Avatar answered Sep 20 '22 19:09

Festus Tamakloe


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:

enter image description here

like image 26
Ranjithkumar Avatar answered Sep 23 '22 19:09

Ranjithkumar