Android
android.widget
public class

android.widget.ToggleButton

java.lang.Object
android.view.View Drawable.Callback KeyEvent.Callback
android.widget.TextView ViewTreeObserver.OnPreDrawListener
android.widget.Button
android.widget.CompoundButton Checkable
android.widget.ToggleButton

ToggleButton is a widget that displays checked/unchecked states as a button with a "light" indicator and by default accompanied with the text "ON" or "OFF".

Summary

XML Attributes

Attribute name Related methods  
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. 
XML Attributes inherited from class android.widget.TextView
XML Attributes inherited from class android.view.View
Constants inherited from class android.view.View
Fields inherited 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  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.
Methods inherited from class android.widget.CompoundButton
Methods inherited from class android.widget.TextView
Methods inherited from class android.view.View
Methods inherited from class java.lang.Object
Methods inherited from interface android.graphics.drawable.Drawable.Callback
Methods inherited from interface android.view.KeyEvent.Callback
Methods inherited from interface android.view.ViewTreeObserver.OnPreDrawListener
Methods inherited from interface android.widget.Checkable

Details

XML Attributes

android:disabledAlpha

The alpha to apply to the indicator when disabled.

Must be a floating point value, such as "1.2".

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol disabledAlpha.

Related Methods

android:textOff

The text for the button when it is not checked.

Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character.

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol textOff.

Related Methods

android:textOn

The text for the button when it is checked.

Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character.

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol textOn.

Related Methods

Public Constructors

public ToggleButton(Context context, AttributeSet attrs, int defStyle)

public ToggleButton(Context context, AttributeSet attrs)

public ToggleButton(Context context)

Public Methods

public CharSequence getTextOff()

Returns the text for when the button is not in the checked state.

Returns

  • The text.

public CharSequence getTextOn()

Returns the text for when the button is in the checked state.

Returns

  • The text.

public void setBackgroundDrawable(Drawable d)

Set the background to a given Drawable, or remove the background. If the background has padding, this View's padding is set to the background's padding. However, when a background is removed, this View's padding isn't touched. If setting the padding is desired, please use setPadding(int, int, int, int).

Parameters

d The Drawable to use as the background, or null to remove the background

public void setChecked(boolean checked)

Changes the checked state of this button.

Parameters

checked true to check the button, false to uncheck it

public void setTextOff(CharSequence textOff)

Sets the text for when the button is not in the checked state.

Parameters

textOff The text.

public void setTextOn(CharSequence textOn)

Sets the text for when the button is in the checked state.

Parameters

textOn The text.

Protected Methods

protected 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.

Be sure to call through to the superclass when overriding this function.

protected void onFinishInflate()

Finalize inflating a view from XML. This is called as the last phase of inflation, after all child views have been added.

Even if the subclass overrides onFinishInflate, they should always be sure to call the super method, so that we get called.

Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:56