Added in API level 1

CompoundButton


abstract class CompoundButton : Button, Checkable
kotlin.Any
   ↳ android.view.View
   ↳ android.widget.TextView
   ↳ android.widget.Button
   ↳ android.widget.CompoundButton

A button with two states, checked and unchecked. When the button is pressed or clicked, the state changes automatically.

XML attributes

See CompoundButton Attributes, Button, TextView Attributes, View Attributes

Summary

Nested classes
abstract

Interface definition for a callback to be invoked when the checked state of a compound button changed.

Inherited XML attributes
Inherited constants
Public constructors

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

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

CompoundButton(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

Public methods
open Unit

open Unit

open CharSequence!

open Int

Describes the autofill type of this view, so an android.service.autofill.AutofillService can create the proper AutofillValue when autofilling the view.

open AutofillValue?

open Drawable?

open BlendMode?

open ColorStateList?

open PorterDuff.Mode?

open Int

open Int

open Boolean

open Unit

open Unit

open Parcelable?

open Boolean

open Unit

Sets a drawable as the compound button image given its resource identifier.

open Unit

Sets a drawable as the compound button image.

open Unit

Sets the button of this CompoundButton to the specified Icon.

open Unit

Specifies the blending mode used to apply the tint specified by setButtonTintList(android.content.res.ColorStateList)} to the button drawable.

open Unit

Applies a tint to the button drawable.

open Unit

Specifies the blending mode used to apply the tint specified by setButtonTintList(android.content.res.ColorStateList)} to the button drawable.

open Unit
setChecked(checked: Boolean)

Changes the checked state of this button.

open Unit

Register a callback to be invoked when the checked state of this button changes.

open Unit
setStateDescription(stateDescription: CharSequence?)

This function is called when an instance or subclass sets the state description.

open Unit

Protected methods
open Unit

open IntArray!

open Unit
onDraw(canvas: Canvas)

open Boolean

If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying.

Inherited functions
Inherited properties

Public constructors

CompoundButton

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

CompoundButton

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

CompoundButton

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

CompoundButton

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

Public methods

autofill

Added in API level 26
open fun autofill(value: AutofillValue!): Unit
Parameters
value AutofillValue!: value to be autofilled.

drawableHotspotChanged

Added in API level 21
open fun drawableHotspotChanged(
    x: Float,
    y: Float
): Unit
Parameters
x Float: hotspot x coordinate
y Float: hotspot y coordinate

getAccessibilityClassName

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

getAutofillType

Added in API level 26
open fun getAutofillType(): Int

Describes the autofill type of this view, so an android.service.autofill.AutofillService can create the proper AutofillValue when autofilling the view.

By default returns AUTOFILL_TYPE_NONE, but views should override it to properly support the Autofill Framework.

Return
Int Value is android.view.View#AUTOFILL_TYPE_NONE, android.view.View#AUTOFILL_TYPE_TEXT, android.view.View#AUTOFILL_TYPE_TOGGLE, android.view.View#AUTOFILL_TYPE_LIST, or android.view.View#AUTOFILL_TYPE_DATE

getAutofillValue

Added in API level 26
open fun getAutofillValue(): AutofillValue?
Return
AutofillValue? current text, null if the text is not editable

getButtonDrawable

Added in API level 23
open fun getButtonDrawable(): Drawable?
Return
Drawable? the drawable used as the compound button image This value may be null.

getButtonTintBlendMode

Added in API level 29
open fun getButtonTintBlendMode(): BlendMode?
Return
BlendMode? the blending mode used to apply the tint to the button drawable This value may be null.

getButtonTintList

Added in API level 21
open fun getButtonTintList(): ColorStateList?
Return
ColorStateList? the tint applied to the button drawable This value may be null.

getButtonTintMode

Added in API level 21
open fun getButtonTintMode(): PorterDuff.Mode?
Return
PorterDuff.Mode? the blending mode used to apply the tint to the button drawable This value may be null.

getCompoundPaddingLeft

Added in API level 1
open fun getCompoundPaddingLeft(): Int

getCompoundPaddingRight

Added in API level 1
open fun getCompoundPaddingRight(): Int

isChecked

Added in API level 1
open fun isChecked(): Boolean
Return
Boolean The current checked state of the view

jumpDrawablesToCurrentState

Added in API level 11
open fun jumpDrawablesToCurrentState(): Unit

onRestoreInstanceState

Added in API level 1
open fun onRestoreInstanceState(state: Parcelable!): Unit
Parameters
state Parcelable!: The frozen state that had previously been returned by onSaveInstanceState.

onSaveInstanceState

Added in API level 1
open fun onSaveInstanceState(): Parcelable?
Return
Parcelable? Returns a Parcelable object containing the view's current dynamic state, or null if there is nothing interesting to save.

performClick

Added in API level 1
open fun performClick(): Boolean
Return
Boolean True there was an assigned OnClickListener that was called, false otherwise is returned.

setButtonDrawable

Added in API level 1
open fun setButtonDrawable(resId: Int): Unit

Sets a drawable as the compound button image given its resource identifier.

Parameters
resId Int: the resource identifier of the drawable

setButtonDrawable

Added in API level 1
open fun setButtonDrawable(drawable: Drawable?): Unit

Sets a drawable as the compound button image.

Parameters
drawable Drawable?: the drawable to set This value may be null.

setButtonIcon

Added in API level 31
open fun setButtonIcon(icon: Icon?): Unit

Sets the button of this CompoundButton to the specified Icon.

Parameters
icon Icon?: an Icon holding the desired button, or null to clear the button

setButtonTintBlendMode

Added in API level 29
open fun setButtonTintBlendMode(tintMode: BlendMode?): Unit

Specifies the blending mode used to apply the tint specified by setButtonTintList(android.content.res.ColorStateList)} to the button drawable. The default mode is PorterDuff.Mode#SRC_IN.

Parameters
tintMode BlendMode?: the blending mode used to apply the tint, may be null to clear tint

setButtonTintList

Added in API level 21
open fun setButtonTintList(tint: ColorStateList?): Unit

Applies a tint to the button drawable. Does not modify the current tint mode, which is PorterDuff.Mode#SRC_IN by default.

Subsequent calls to setButtonDrawable(android.graphics.drawable.Drawable) will automatically mutate the drawable and apply the specified tint and tint mode using Drawable#setTintList(ColorStateList).

Parameters
tint ColorStateList?: the tint to apply, may be null to clear tint

setButtonTintMode

Added in API level 21
open fun setButtonTintMode(tintMode: PorterDuff.Mode?): Unit

Specifies the blending mode used to apply the tint specified by setButtonTintList(android.content.res.ColorStateList)} to the button drawable. The default mode is PorterDuff.Mode#SRC_IN.

Parameters
tintMode PorterDuff.Mode?: the blending mode used to apply the tint, may be null to clear tint

setChecked

Added in API level 1
open fun setChecked(checked: Boolean): Unit

Changes the checked state of this button.

Parameters
checked Boolean: true to check the button, false to uncheck it

setOnCheckedChangeListener

Added in API level 1
open fun setOnCheckedChangeListener(listener: CompoundButton.OnCheckedChangeListener?): Unit

Register a callback to be invoked when the checked state of this button changes.

Parameters
listener CompoundButton.OnCheckedChangeListener?: the callback to call on checked state change This value may be null.

setStateDescription

Added in API level 30
open fun setStateDescription(stateDescription: CharSequence?): Unit

This function is called when an instance or subclass sets the state description. Once this is called and the argument is not null, the app developer will be responsible for updating state description when checked state changes and we will not set state description in setChecked. App developers can restore the default behavior by setting the argument to null. If setChecked is called first and then setStateDescription is called, two state change events will be merged by event throttling and we can still get the correct state description.

Parameters
stateDescription CharSequence?: The state description. This value may be null.

toggle

Added in API level 1
open fun toggle(): Unit

Protected methods

drawableStateChanged

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

onCreateDrawableState

Added in API level 1
protected open fun onCreateDrawableState(extraSpace: Int): IntArray!
Parameters
extraSpace Int: if non-zero, this is the number of extra entries you would like in the returned array in which you can place your own states.
Return
IntArray! Returns an array holding the current Drawable state of the view.

onDraw

Added in API level 1
protected open fun onDraw(canvas: Canvas): Unit
Parameters
canvas Canvas: the canvas on which the background will be drawn This value cannot be null.

verifyDrawable

Added in API level 1
protected open fun verifyDrawable(who: Drawable): Boolean

If your view subclass is displaying its own Drawable objects, it should override this function and return true for any Drawable it is displaying. This allows animations for those drawables to be scheduled.

Be sure to call through to the super class when overriding this function.
If you override this method you must call through to the superclass implementation.

Parameters
who Drawable: This value cannot be null.
Return
Boolean boolean If true then the Drawable is being displayed in the view; else false and it is not allowed to animate.