Selector on Button Example - ANDROID - Helper

Thursday, July 04, 2013

Selector on Button Example


Android – Selector on Button Example

Source button.xml

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

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

<item android:drawable="@drawable/button_pressed"
android:state_pressed="true" />

<item android:drawable="@drawable/button_normal"
android:state_focused="true" />

<item android:drawable="@drawable/button_normal" />

</selector>


Source main.xml

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />

<Button
android:id="@+id/button1"
android:layout_width="80dp"
android:layout_height="40dp"
android:background="@drawable/button"
android:textColor="#ffffff"
android:text="Button" />

</LinearLayout>

The output will be

 


3 comments:

  1. I am not sure where you're getting your info, but great topic. I needs to spend some time learning more or understanding more. Thanks for magnificent information I was looking for this info for my mission.
    android application development

    ReplyDelete
  2. Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.
    Android Training in chennai | Best Android Training in chennai|Android Training in chennai with placement | Android Training in velachery

    ReplyDelete