Friday 18 May 2012

Give Effects to Buttons in android

To give effect Like we feel that button has been pressed in our application, use following code.
create one xml file in your drawable directory(or where you put your images). paste this code in it and call this file in your buttons background.

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">

// Button Focused Pressed
<item android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/call_end_2" />
// Button Pressed
<item android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/call_end_1" />
// Button Default Image
<item android:drawable="@drawable/call_end" />
</selector>
now call this file in your xml file i.e 

<Button
            android:id="@+id/btn_startcall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/your_button_efffect_xml" />
   

No comments: