Added in API level 1

ToggleButton

open class ToggleButton : CompoundButton
kotlin.Any
   ↳ android.view.View
   ↳ android.widget.TextView
   ↳ android.widget.Button
   ↳ android.widget.CompoundButton
   ↳ android.widget.ToggleButton

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

See the Toggle Buttons guide.

Summary

XML attributes
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.
Inherited XML attributes
Inherited constants
Public constructors
ToggleButton(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

ToggleButton(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

ToggleButton(context: Context!, attrs: AttributeSet!)

ToggleButton(context: Context!)

Public methods
open CharSequence!

open Float

Returns the alpha value of the button when it is disabled

open CharSequence!

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

open CharSequence!

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

open Unit

open Unit
setChecked(checked: Boolean)

open Unit

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

open Unit

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

Protected methods
open Unit

open Unit

Inherited functions
Inherited properties

XML attributes

android:disabledAlpha

android:disabledAlpha
The alpha to apply to the indicator when disabled.

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

android:textOff

android:textOff
The text for the button when it is not checked.

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

android:textOn

android:textOn
The text for the button when it is checked.

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

Public constructors

ToggleButton

Added in API level 1
ToggleButton(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int,
    defStyleRes: Int)

ToggleButton

Added in API level 1
ToggleButton(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int)

ToggleButton

Added in API level 1
ToggleButton(
    context: Context!,
    attrs: AttributeSet!)

ToggleButton

Added in API level 1
ToggleButton(context: Context!)

Public methods

getAccessibilityClassName

Added in API level 23
open fun getAccessibilityClassName(): CharSequence!

getDisabledAlpha

Added in API level 29
open fun getDisabledAlpha(): Float

Returns the alpha value of the button when it is disabled

Return
Float the alpha value, 0.0-1.0 Value is between 0.0 and 1.0 inclusive

getTextOff

Added in API level 1
open fun getTextOff(): CharSequence!

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

Return
CharSequence! The text.

getTextOn

Added in API level 1
open fun getTextOn(): CharSequence!

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

Return
CharSequence! The text.

setBackgroundDrawable

Added in API level 1
open fun setBackgroundDrawable(d: Drawable!): Unit

setChecked

Added in API level 1
open fun setChecked(checked: Boolean): Unit
Parameters
checked Boolean: true to check the button, false to uncheck it

setTextOff

Added in API level 1
open fun setTextOff(textOff: CharSequence!): Unit

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

Parameters
textOff CharSequence!: The text.

setTextOn

Added in API level 1
open fun setTextOn(textOn: CharSequence!): Unit

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

Parameters
textOn CharSequence!: The text.

Protected methods

drawableStateChanged

Added in API level 1
protected open fun drawableStateChanged(): Unit

onFinishInflate

Added in API level 1
protected open fun onFinishInflate(): Unit