Multi-State Toggle Button

I implemented a multi-state toggle button, the source code is here This is how it looks: And it’s quite easy to use it: <org.honorato.multistatetogglebutton.MultiStateToggleButton android:id=”@+id/mstb_multi_id” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_marginTop=”10dip” mstb:values=”@array/planets_array” /> In your activity: MultiStateToggleButton button2 = (MultiStateToggleButton) this.findViewById(R.id.mstb_multi_id); button2.setOnValueChangedListener(new ToggleButton.OnValueChangedListener() { @Override public void onValueChanged(int value) { Log.d(TAG, “Value: ” + value); } });

How to make a radio button look like a toggle button

Depending on which browsers you aim to support, you could use the :checked pseudo-class selector in addition to hiding the radio buttons. Using this HTML: <input type=”radio” id=”toggle-on” name=”toggle” checked ><label for=”toggle-on”>On</label ><input type=”radio” id=”toggle-off” name=”toggle” ><label for=”toggle-off”>Off</label> You could use something like the following CSS: input[type=”radio”].toggle { display: none; } input[type=”radio”].toggle:checked + label { … Read more

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=””

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>

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