MaterialCheckBox

A class that creates a Material Themed CheckBox.

This class uses attributes from the Material Theme to style a CheckBox. It behaves similarly to AppCompatCheckBox, but with color changes and the support of the indeterminate state, and an independent error state.

The checkbox is composed of an app:buttonCompat button drawable (the squared icon) and an app:buttonIcon icon drawable (the checkmark icon) layered on top of it. Their colors can be customized via app:buttonTint and app:buttonIconTint respectively.

If setting a custom app:buttonCompat, make sure to also set app:buttonIcon if an icon is desired. The checkbox does not support having a custom app:buttonCompat and preserving the default app:buttonIcon checkmark at the same time.

For more information, see the component developer guidance and design guidelines.

Constructors

Link copied to clipboard
constructor(context: Context)
constructor(context: Context, @Nullable attrs: AttributeSet)
constructor(context: Context, @Nullable attrs: AttributeSet, defStyleAttr: Int)

Types

Link copied to clipboard
Values for the state of the checkbox.
Link copied to clipboard
Callback interface invoked when one of three independent checkbox states change.
Link copied to clipboard
Callback interface invoked when the checkbox error state changes.

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open var checkedState: Int
Link copied to clipboard
The checked state of the checkbox.
Link copied to clipboard
The indeterminate state of the checkbox.
Link copied to clipboard
The unchecked state of the checkbox.

Functions

Link copied to clipboard
Adds a OnCheckedStateChangedListener that will be invoked when the checkbox state changes.
Link copied to clipboard
Adds a OnErrorChangedListener that will be invoked when the checkbox error state changes.
Link copied to clipboard
Link copied to clipboard
Remove all previously added OnErrorChangedListeners.
Link copied to clipboard
Returns true if this MaterialCheckBox will center the checkbox icon when there is no text.
Link copied to clipboard
open fun isChecked(): Boolean
Link copied to clipboard
open fun isErrorShown(): Boolean
Returns whether the checkbox is on error state.
Link copied to clipboard
Returns true if this MaterialCheckBox defaults to colors from a Material Theme.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Remove a listener that was previously added via addOnErrorChangedListener
Link copied to clipboard
open fun setButtonDrawable(@DrawableRes resId: Int)
Link copied to clipboard
Sets the button icon drawable of the checkbox.
Link copied to clipboard
Link copied to clipboard
open fun setCenterIfNoTextEnabled(centerIfNoTextEnabled: Boolean)
Sets whether this MaterialCheckBox should center the checkbox icon when there is no text.
Link copied to clipboard
open fun setChecked(checked: Boolean)
Link copied to clipboard
open fun setEnabled(enabled: Boolean)
Link copied to clipboard
Sets the accessibility label to be used for the error state announcement by screen readers.
Link copied to clipboard
open fun setErrorShown(errorShown: Boolean)
Sets whether the checkbox should be on error state.
Link copied to clipboard
Link copied to clipboard
open fun setUseMaterialThemeColors(useMaterialThemeColors: Boolean)
Forces the MaterialCheckBox to use colors from a Material Theme.
Link copied to clipboard
open fun toggle()