ToggleButton

// By:Team // No Comment

Email this to someonePrint this pageShare on Google+0Share on Facebook0Tweet about this on TwitterShare on LinkedIn0Share on Reddit0Pin on Pinterest0Share on StumbleUpon6

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.

Example

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/MainActivity.java 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.

MainActivity.java

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

activity_main.xml

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

strings.xml

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

AndroidManifest.xml

Following is the default content of AndroidManifest.xml:

Output

The following screen will appear:

android_togglebutton_control1

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

android_togglebutton_control2

Email this to someonePrint this pageShare on Google+0Share on Facebook0Tweet about this on TwitterShare on LinkedIn0Share on Reddit0Pin on Pinterest0Share on StumbleUpon6

About Team

Browse Archived Articles by Team

Related

Sorry. There are no related articles at this time.