Follow this method so that your ToogleButton red when turned on and green when OFF
First , create tooglebutton_selector.xml in the drop down folder
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/togglebutton_on" android:state_checked="true" /> <item android:drawable="@drawable/togglebutton_off" android:state_checked="false" /> </selector>
Second , create togglebutton_on.xml in the excerpt folder
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#ff0000" /> // red color </shape>
Third , create togglebutton_off.xml in the drop down folder
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#00FF00" /> // green color </shape>
Finally in your ToggleButton
<ToggleButton android:id="@+id/btnMon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/tooglebutton_selector"
Phan Van Linh Aug 14 '16 at 3:54 on 2016-08-14 03:54
source share