Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Button border shadow

Shadow property in Button view gives shadow to text. How can I give shadow to right and bottom border of a Button?As shown below:

enter image description here

like image 917
AndroidDev Avatar asked Apr 10 '12 07:04

AndroidDev


2 Answers

You can try it. I use it in my project. I give shadow to right and bottom border of a Button.

Button xml

<Button
      android:id="@+id/buttonSignIn"
      android:layout_width="fill_parent"
      android:layout_height="50dp"
      android:background="@drawable/button_dropshadow"
      android:textColor="000000"
      android:text="Sign In" />

In drawable file add button_dropshadow.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <layer-list>
        <item android:left="5dp" android:top="5dp">
            <shape>
                <corners android:radius="3dp" />
                <solid android:color="#000000" />
            </shape>
        </item>
        <item android:bottom="2dp" android:right="2dp">
            <shape>
                <gradient android:angle="270" 
                    android:endColor="#ffffff" android:startColor="#ffffff" />
                <stroke android:width="1dp" android:color="#000000" />
                <corners android:radius="4dp" />
                <padding android:bottom="10dp" android:left="10dp" 
                    android:right="10dp" android:top="10dp" />
            </shape>
        </item>
    </layer-list>
</item>

</selector>

Thank you.

like image 200
Md Imran Choudhury Avatar answered Oct 20 '22 00:10

Md Imran Choudhury


Try making your own button 9-patch image with selector:

btn_normal.9.png: Normal

btn_pressed.9.png: Pressed

btn_focused.9.png: Focused

btn_selector.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true" android:drawable="@drawable/btn_focused" />
    <item android:state_focused="true" android:drawable="@drawable/btn_focused" />
    <item android:state_pressed="true" android:drawable="@drawable/btn_pressed" />
    <item android:drawable="@drawable/btn_normal" />
</selector>

and add android:background="@drawable/btn_selector" in button's attributes.

like image 44
The Badak Avatar answered Oct 20 '22 00:10

The Badak