Following are the important attributes related to ToggleButton control. You can check Android official documentation for complete list of attributes and related methods which you can use to change these attributes are run time.

Attribute Description
android:disabledAlpha This is the alpha to apply to the indicator when disabled.
android:textOff This is the text for the button when it is not checked.
android:textOn This is the text for the button when it is checked.

Inherited from android.widget.TextView Class:

Attribute Description
android:autoText If set, specifies that this TextView has a textual input method and automatically corrects some common spelling errors.
android:drawableBottom This is the drawable to be drawn below the text.
android:drawableRight This is the drawable to be drawn to the right of the text.
android:editable If set, specifies that this TextView has an input method.
android:text This is the Text to display.

Inherited from android.view.View Class:

Attribute Description
android:background This is a drawable to use as the background.
android:contentDescription This defines text that briefly describes content of the view.
android:id This supplies an identifier name for this view,
android:onClick This is the name of the method in this View’s context to invoke when the view is clicked.
android:visibility This controls the initial visibility of the view.


This example will take you through simple steps to show how to create your own Android application using Linear Layout and ToggleButton.

Step Description
1 You will use Eclipse IDE to create an Android application and name it as GUIDemo7 under a package com.example.guidemo7 as explained in the Hello World Example chapter.
2 Modify src/ file to add a click event.
2 Modify the default content of res/layout/activity_main.xml file to include Android UI control.
3 Define required constants in res/values/strings.xml file
4 Run the application to launch Android emulator and verify the result of the changes done in the application.

Following is the content of the modified main activity filesrc/com.example.guidemo7/ This file can include each of the fundamental lifecycle methods.


Following will be the content of res/layout/activity_main.xml file:


Following will be the content of res/values/strings.xml to define these new constants:


Following is the default content of AndroidManifest.xml:


The following screen will appear:


The following screen will appear, conditions are shown when state of both the toggle buttons are changed: