Android Switch Button Example
https://www.viralandroid.com/2015/11/android-switch-button-example.html
In this tutorial, I am going to show how to use switch button in android application. A Switch is a two-state button through which only two states ON and OFF can be selected and it is one of the most use android user interface (UI) component in application setting. Switch button is only supported in android 4.0 and larger device. Following are the simple steps to implement Switch button in android.
Related:
Android Radio Button Example
Android SeekBar Example
Android CheckBox Example
That’s all. Now, run your application which will look like output given below.
Output:
Related:
Android Radio Button Example
Android SeekBar Example
Android CheckBox Example
Android Example: How to use Switch Button in Android
XML Layout File
res/layout/switch_button_example.xmlJava Activity File
src/MainActivity.javaThat’s all. Now, run your application which will look like output given below.
Output:
![]() |
Switch Button in Android |