Android: Specify two different images for togglebutton using XML

Your code is fine. However, the toggle button will display the first item in your selector that it matches, so the default should come last. Arrange the items in the following manner to ensure they will all be utilized: <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:state_checked=”true” android:state_pressed=”true” /> //currently pressed turning the toggle on <item android:state_pressed=”true” /> //currently … Read more

Android toggle button custom look

create toggle_selector.xml in res/drawable <?xml version=”1.0″ encoding=”utf-8″?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <item android:drawable=”@drawable/toggle_on” android:state_checked=”true”/> <item android:drawable=”@drawable/toggle_off” android:state_checked=”false”/> </selector> apply the selector to your toggle button <ToggleButton android:id=”@+id/chkState” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:background=”@drawable/toggle_selector” android:textOff=”” android:textOn=””/> Note: for removing the text i used following in above code textOff=”” textOn=””

Change “on” color of a Switch

Late to party but this is how I did Style <style name=”SCBSwitch” parent=”Theme.AppCompat.Light”> <!– active thumb & track color (30% transparency) –> <item name=”colorControlActivated”>#46bdbf</item> <!– inactive thumb color –> <item name=”colorSwitchThumbNormal”>#f1f1f1 </item> <!– inactive track color (30% transparency) –> <item name=”android:colorForeground”>#42221f1f </item> </style> Colors Layout <android.support.v7.widget.SwitchCompat android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_alignParentRight=”true” android:checked=”false” android:theme=”@style/SCBSwitch” /> Result See change … Read more

Toggle button using two image on different state

Do this: <ToggleButton android:id=”@+id/toggle” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:background=”@drawable/check” <!–check.xml–> android:layout_margin=”10dp” android:textOn=”” android:textOff=”” android:focusable=”false” android:focusableInTouchMode=”false” android:layout_centerVertical=”true”/> create check.xml in drawable folder <?xml version=”1.0″ encoding=”utf-8″?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”> <!– When selected, use grey –> <item android:drawable=”@drawable/selected_image” android:state_checked=”true” /> <!– When not selected, use white–> <item android:drawable=”@drawable/unselected_image” android:state_checked=”false”/> </selector>