public class

ToggleButton

extends CompoundButton
java.lang.Object
   ↳ android.view.View
     ↳ android.widget.TextView
       ↳ android.widget.Button
         ↳ android.widget.CompoundButton
           ↳ android.widget.ToggleButton

Class Overview

Displays checked/unchecked states as a button with a "light" indicator and by default accompanied with the text "ON" or "OFF".

See the Form Stuff tutorial.

Summary

XML Attributes
Attribute Name Related Method Description
android:disabledAlpha The alpha to apply to the indicator when disabled. 
android:textOff The text for the button when it is not checked. 
android:textOn The text for the button when it is checked. 
[Expand]
Inherited XML Attributes
From class android.widget.TextView
From class android.view.View
[Expand]
Inherited Constants
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
Public Constructors
ToggleButton(Context context, AttributeSet attrs, int defStyle)
ToggleButton(Context context, AttributeSet attrs)
ToggleButton(Context context)
Public Methods
CharSequence getTextOff()
Returns the text for when the button is not in the checked state.
CharSequence getTextOn()
Returns the text for when the button is in the checked state.
void onPopulateAccessibilityEvent(AccessibilityEvent event)
Called from dispatchPopulateAccessibilityEvent(AccessibilityEvent) giving a chance to this View to populate the accessibility event with its text content.
void setBackgroundDrawable(Drawable d)
Set the background to a given Drawable, or remove the background.
void setChecked(boolean checked)

Changes the checked state of this button.

void setTextOff(CharSequence textOff)
Sets the text for when the button is not in the checked state.
void setTextOn(CharSequence textOn)
Sets the text for when the button is in the checked state.
Protected Methods
void drawableStateChanged()
This function is called whenever the state of the view changes in such a way that it impacts the state of drawables being shown.
void onFinishInflate()
Finalize inflating a view from XML.
[Expand]
Inherited Methods
From class android.widget.CompoundButton
From class android.widget.TextView
From class android.view.View
From class java.lang.Object