ToggleButton in Android

Toggle button is mostly used when we need to display “ON / OFF” states for button. Toggle button is two states button such as a checked/unchecked. Toggle button used in my old device, see below,

android-toggle-button-example-sample-skynils

some useful attribute of toggle button below.

  • android:checked :  set is toggle button checked or unchecked.
  • android:textOn : set text on toggle button when is checked.
  • android:textOff : set text on toggle button when is unchecked.
  • android:onClick : Method name which is defined in java file for this button.

Let’s see one simple example.activity_main.xml

MainActivity.java

Now run project. Our output looks like below.

android-toggle-button-example-output-skynils

Download Project.
downlod

Now see next tutorial Switch Button in Android.