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,


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

Now run project. Our output looks like below.


Download Project.

Now see next tutorial Switch Button in Android.

(Visited 792 times, 1 visits today)