Change Togglebutton Color
How to change the color of toggleButton in listView? This is how I deigned my toggleButton
Solution 1:
try this way.
ToggleButton :
<ToggleButtonandroid:layout_width="50dp"android:layout_height="50dp"android:textOn="On"android:textOff="Off"android:textSize="20sp"android:background="@drawable/toggle_day_bg_selector" />
toggle_day_bg_selector.xml
<?xml version="1.0" encoding="utf-8"?><selectorxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:drawable="@drawable/toggle_off"android:state_checked="false"/><itemandroid:drawable="@drawable/toggle_on"android:state_checked="true"/></selector>
toggle_on.xml
<?xml version="1.0" encoding="utf-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval"
><solidandroid:color="@color/red" /></shape>
toggle_off.xml
<?xml version="1.0" encoding="utf-8"?><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval"><solidandroid:color="@color/green" /></shape>
Hope this will help.
EDIT :
use this drawable files for showing images on ToggleButton
toggle_off.xml
<?xml version="1.0" encoding="utf-8"?><layer-listxmlns:android="http://schemas.android.com/apk/res/android" ><item><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval" ><solidandroid:color="@android:color/holo_green_dark" /></shape></item><itemandroid:drawable="@drawable/ic_launcher"><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval" ><solidandroid:color="@android:color/holo_green_dark" /></shape></item></layer-list>
toggle_on.xml
<?xml version="1.0" encoding="utf-8"?><layer-listxmlns:android="http://schemas.android.com/apk/res/android" ><item><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval" ><solidandroid:color="@android:color/holo_red_dark" /></shape></item><itemandroid:drawable="@drawable/ic_launcher"><shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="oval" ><solidandroid:color="@android:color/holo_red_dark" /></shape></item></layer-list>
happy coding..
Post a Comment for "Change Togglebutton Color"