Sunday, October 14, 2012

Change Background of Android ToggleButton on check state change

How you change background of Toggle Button when you toggle the check state of button ?



using selector in android

see example of background.xml



<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/bar2_02" android:state_checked="true"/>
    <item android:drawable="@drawable/bar2_01" android:state_checked="false"/>
    <item android:drawable="@drawable/bar2_01"></item>
</selector>




for call this selector xml(background.xml) in toogle button



<ToggleButton
                android:id="@+id/sbar2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/background.xml"
                android:button="@null"
                android:textOff=""
                android:textOn="" />



2 comments:

  1. Congratulations guys, quality information you have given!!!..Its really useful blog. Thanks for sharing this useful information
    Android Training institute in chennai with placement | Android Training in chennai

    ReplyDelete
  2. sands casino - Treasure Island Casino Resort
    At Sands 샌즈카지노 Casino Resort in Paradise Beach, you'll experience the 1xbet korean majestic and majestic Las Vegas of the Sierra Nevada. At Sands Casino Resort, ‎Casino · ‎Entertainment · 바카라 ‎Shows

    ReplyDelete