Switch Button in Android

In Android Switch is button which have only two state “ON/OFF”. Switch is mostly used in the setting UI components.

See Use of switch in my old deveice.

android-switch-button-example-sample-skynils

Switch is such a like ToggleButton in Android. Almost attribute and functionality is same as ToggleButton. But you have to note that Switch is introduced in Android 4.0 ( API 14 ) so we can only use this in API 14 or higher.

Let’s see one simple example. Create Project and set Minimum SDK 14. and then follow this code.
activity_main.xml

MainActivity.java

Now run project. Our output looks like below,

android-switch-button-example-output-skynils

Download Project.

downlod