# MaterialCheckBox

[View Source](https://github.com/material-components/material-components-android/blob/1.14.0/lib/java/com/google/android/material/checkbox/MaterialCheckBox.java)

*** ** * ** ***


```
public class MaterialCheckBox
```

<br />

*** ** * ** ***

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](https://github.com/material-components/material-components-android/blob/master/docs/components/Checkbox.md) and [design guidelines](https://material.io/components/checkbox/overview).

## Summary

| ### Nested types |
|---|
| `public interface https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox.OnCheckedStateChangedListener` Callback interface invoked when one of three independent checkbox states change. |
| `public interface https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox.OnErrorChangedListener` Callback interface invoked when the checkbox error state changes. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#STATE_CHECKED() = 1` The checked state of the checkbox. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#STATE_INDETERMINATE() = 2` The indeterminate state of the checkbox. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#STATE_UNCHECKED() = 0` The unchecked state of the checkbox. |

| ### Public fields |
|---|---|
| `Drawable` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#buttonDrawable()` |
| `Drawable` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#buttonIconDrawable()` |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#buttonIconTintList()` |
| `Mode` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#buttonIconTintMode()` |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#buttonTintList()` |
| `int` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#checkedState()` |
| `https://developer.android.com/reference/java/lang/CharSequence` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#errorAccessibilityLabel()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#MaterialCheckBox(Context)(Context context)` |
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#MaterialCheckBox(Context,AttributeSet)(Context context, AttributeSet attrs)` |
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#MaterialCheckBox(Context,AttributeSet,int)(Context context, AttributeSet attrs, int defStyleAttr)` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#addOnCheckedStateChangedListener(com.google.android.material.checkbox.MaterialCheckBox.OnCheckedStateChangedListener)( https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox.OnCheckedStateChangedListener listener )` Adds a `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox.OnCheckedStateChangedListener` that will be invoked when the checkbox state changes. |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#addOnErrorChangedListener(com.google.android.material.checkbox.MaterialCheckBox.OnErrorChangedListener)( https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox.OnErrorChangedListener listener )` Adds a `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox.OnErrorChangedListener` that will be invoked when the checkbox error state changes. |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#clearOnCheckedStateChangedListeners()()` Removes all previously added `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox.OnCheckedStateChangedListener`s. |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#clearOnErrorChangedListeners()()` Remove all previously added `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox.OnErrorChangedListener`s. |
| `Drawable` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#getButtonDrawable()()` |
| `Drawable` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#getButtonIconDrawable()()` Returns the button icon drawable, or null if none. |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#getButtonIconTintList()()` Returns the checkbox button icon's tint list. |
| `Mode` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#getButtonIconTintMode()()` Returns the blending mode used to apply the tint to the button icon drawable. |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#getButtonTintList()()` |
| `int` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#getCheckedState()()` Returns the current checkbox state. |
| `https://developer.android.com/reference/java/lang/CharSequence` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#getErrorAccessibilityLabel()()` Returns the accessibility label used for the error state announcement. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#isCenterIfNoTextEnabled()()` Returns true if this `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox` will center the checkbox icon when there is no text. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#isChecked()()` |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#isErrorShown()()` Returns whether the checkbox is on error state. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#isUseMaterialThemeColors()()` Returns true if this `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox` defaults to colors from a Material Theme. |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)(AccessibilityNodeInfo info)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#onRestoreInstanceState(Parcelable)(Parcelable state)` |
| `Parcelable` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#onSaveInstanceState()()` |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#removeOnCheckedStateChangedListener(com.google.android.material.checkbox.MaterialCheckBox.OnCheckedStateChangedListener)( https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox.OnCheckedStateChangedListener listener )` Removes a listener that was previously added via `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#addOnCheckedStateChangedListener(com.google.android.material.checkbox.MaterialCheckBox.OnCheckedStateChangedListener)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#removeOnErrorChangedListener(com.google.android.material.checkbox.MaterialCheckBox.OnErrorChangedListener)( https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox.OnErrorChangedListener listener )` Remove a listener that was previously added via `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#addOnErrorChangedListener(com.google.android.material.checkbox.MaterialCheckBox.OnErrorChangedListener)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setButtonDrawable(Drawable)(Drawable drawable)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setButtonDrawable(int)(int resId)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setButtonIconDrawable(Drawable)(Drawable drawable)` Sets the button icon drawable of the checkbox. |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setButtonIconDrawableResource(int)(int resId)` Sets the button icon drawable of the checkbox. |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setButtonIconTintList(ColorStateList)(ColorStateList tintList)` Sets the checkbox button icon's tint list, if an icon is present. |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setButtonIconTintMode(PorterDuff.Mode)(Mode tintMode)` Specifies the blending mode used to apply the tint specified by `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setButtonIconTintList(ColorStateList)`} to the button icon drawable. |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setButtonTintList(ColorStateList)(ColorStateList tintList)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setButtonTintMode(Mode)(Mode tintMode)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setCenterIfNoTextEnabled(boolean)(boolean centerIfNoTextEnabled)` Sets whether this `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox` should center the checkbox icon when there is no text. |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setChecked(boolean)(boolean checked)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setCheckedState(int)(int checkedState)` Sets the `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox.CheckedState` of the checkbox. |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setErrorAccessibilityLabel(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence errorAccessibilityLabel)` Sets the accessibility label to be used for the error state announcement by screen readers. |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setErrorAccessibilityLabelResource(int)(int resId)` Sets the accessibility label to be used for the error state announcement by screen readers. |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setErrorShown(boolean)(boolean errorShown)` Sets whether the checkbox should be on error state. |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setOnCheckedChangeListener(OnCheckedChangeListener)(OnCheckedChangeListener listener)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setStateDescription(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence stateDescription)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setUseMaterialThemeColors(boolean)(boolean useMaterialThemeColors)` Forces the `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox` to use colors from a Material Theme. |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#toggle()()` |

| ### Protected methods |
|---|---|
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#onAttachedToWindow()()` |
| `int[]` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#onCreateDrawableState(int)(int extraSpace)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#onDraw(Canvas)(Canvas canvas)` |

## Constants

### STATE_CHECKED

```
public static final int STATE_CHECKED = 1
```

The checked state of the checkbox.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setCheckedState(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#getCheckedState()` |   |

### STATE_INDETERMINATE

```
public static final int STATE_INDETERMINATE = 2
```

The indeterminate state of the checkbox.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setCheckedState(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#getCheckedState()` |   |

### STATE_UNCHECKED

```
public static final int STATE_UNCHECKED = 0
```

The unchecked state of the checkbox. A checkbox is unchecked by default.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setCheckedState(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#getCheckedState()` |   |

## Public fields

### buttonDrawable

```
public Drawable buttonDrawable
```

### buttonIconDrawable

```
public Drawable buttonIconDrawable
```

### buttonIconTintList

```
public ColorStateList buttonIconTintList
```

### buttonIconTintMode

```
public Mode buttonIconTintMode
```

### buttonTintList

```
public ColorStateList buttonTintList
```

### checkedState

```
public int checkedState
```

### errorAccessibilityLabel

```
public CharSequence errorAccessibilityLabel
```

## Public constructors

### MaterialCheckBox

```
public MaterialCheckBox(Context context)
```

### MaterialCheckBox

```
public MaterialCheckBox(Context context, AttributeSet attrs)
```

### MaterialCheckBox

```
public MaterialCheckBox(Context context, AttributeSet attrs, int defStyleAttr)
```

## Public methods

### addOnCheckedStateChangedListener

```
public void addOnCheckedStateChangedListener(
    MaterialCheckBox.OnCheckedStateChangedListener listener
)
```

Adds a `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox.OnCheckedStateChangedListener` that will be invoked when the checkbox state changes.

Components that add a listener should take care to remove it when finished via `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#removeOnCheckedStateChangedListener(com.google.android.material.checkbox.MaterialCheckBox.OnCheckedStateChangedListener)`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox.OnCheckedStateChangedListener listener` | listener to add |

### addOnErrorChangedListener

```
public void addOnErrorChangedListener(
    MaterialCheckBox.OnErrorChangedListener listener
)
```

Adds a `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox.OnErrorChangedListener` that will be invoked when the checkbox error state changes.

Components that add a listener should take care to remove it when finished via `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#removeOnErrorChangedListener(com.google.android.material.checkbox.MaterialCheckBox.OnErrorChangedListener)`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox.OnErrorChangedListener listener` | listener to add |

### clearOnCheckedStateChangedListeners

```
public void clearOnCheckedStateChangedListeners()
```

Removes all previously added `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox.OnCheckedStateChangedListener`s.

### clearOnErrorChangedListeners

```
public void clearOnErrorChangedListeners()
```

Remove all previously added `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox.OnErrorChangedListener`s.

### getButtonDrawable

```
public Drawable getButtonDrawable()
```

### getButtonIconDrawable

```
public Drawable getButtonIconDrawable()
```

Returns the button icon drawable, or null if none.
This method expects that the icon will be the second layer of a two-layer drawable.

ref com.google.android.material.R.styleable#MaterialCheckBox_buttonIcon

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setButtonIconDrawable(Drawable)` |   |

### getButtonIconTintList

```
public ColorStateList getButtonIconTintList()
```

Returns the checkbox button icon's tint list.

ref com.google.android.material.R.styleable#MaterialCheckBox_buttonIconTint

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setButtonIconTintList(ColorStateList)` |   |

### getButtonIconTintMode

```
public Mode getButtonIconTintMode()
```

Returns the blending mode used to apply the tint to the button icon drawable.

ref com.google.android.material.R.styleable#MaterialSwitch_buttonIconTintMode

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setButtonIconTintMode(PorterDuff.Mode)` |   |

### getButtonTintList

```
public ColorStateList getButtonTintList()
```

### getCheckedState

```
public int getCheckedState()
```

Returns the current checkbox state.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setCheckedState(int)` |   |

### getErrorAccessibilityLabel

```
public CharSequence getErrorAccessibilityLabel()
```

Returns the accessibility label used for the error state announcement.

ref com.google.android.material.R.styleable#MaterialCheckBox_errorAccessibilityLabel

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setErrorAccessibilityLabel(java.lang.CharSequence)` |   |

### isCenterIfNoTextEnabled

```
public boolean isCenterIfNoTextEnabled()
```

Returns true if this `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox` will center the checkbox icon when there is no text.

### isChecked

```
public boolean isChecked()
```

### isErrorShown

```
public boolean isErrorShown()
```

Returns whether the checkbox is on error state.

ref com.google.android.material.R.styleable#MaterialCheckBox_errorShown

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setErrorShown(boolean)` |   |

### isUseMaterialThemeColors

```
public boolean isUseMaterialThemeColors()
```

Returns true if this `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox` defaults to colors from a Material Theme.

### onInitializeAccessibilityNodeInfo

```
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
```

### onRestoreInstanceState

```
public void onRestoreInstanceState(Parcelable state)
```

### onSaveInstanceState

```
public Parcelable onSaveInstanceState()
```

### removeOnCheckedStateChangedListener

```
public void removeOnCheckedStateChangedListener(
    MaterialCheckBox.OnCheckedStateChangedListener listener
)
```

Removes a listener that was previously added via `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#addOnCheckedStateChangedListener(com.google.android.material.checkbox.MaterialCheckBox.OnCheckedStateChangedListener)`

| Parameters |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox.OnCheckedStateChangedListener listener` | listener to remove |

### removeOnErrorChangedListener

```
public void removeOnErrorChangedListener(
    MaterialCheckBox.OnErrorChangedListener listener
)
```

Remove a listener that was previously added via `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#addOnErrorChangedListener(com.google.android.material.checkbox.MaterialCheckBox.OnErrorChangedListener)`

| Parameters |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox.OnErrorChangedListener listener` | listener to remove |

### setButtonDrawable

```
public void setButtonDrawable(Drawable drawable)
```

### setButtonDrawable

```
public void setButtonDrawable(int resId)
```

### setButtonIconDrawable

```
public void setButtonIconDrawable(Drawable drawable)
```

Sets the button icon drawable of the checkbox.
The icon will be layered above the button drawable set by `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setButtonDrawable(Drawable)`.

ref com.google.android.material.R.styleable#MaterialCheckBox_buttonIcon

| Parameters |
|---|---|
| `Drawable drawable` | the icon drawable to be set |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#getButtonIconDrawable()` |   |

### setButtonIconDrawableResource

```
public void setButtonIconDrawableResource(int resId)
```

Sets the button icon drawable of the checkbox.

The icon will be layered above the button drawable set by `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setButtonDrawable(Drawable)`.

ref com.google.android.material.R.styleable#MaterialCheckBox_buttonIcon

| Parameters |
|---|---|
| `int resId` | resource id of the drawable to set, or 0 to clear and remove the icon |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#getButtonIconDrawable()` |   |

### setButtonIconTintList

```
public void setButtonIconTintList(ColorStateList tintList)
```

Sets the checkbox button icon's tint list, if an icon is present.
This method expects that the icon will be the second layer of a two-layer drawable.

ref com.google.android.material.R.styleable#MaterialCheckBox_buttonIconTint

| Parameters |
|---|---|
| `ColorStateList tintList` | the tint to set on the button icon |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#getButtonIconTintList()` |   |

### setButtonIconTintMode

```
public void setButtonIconTintMode(Mode tintMode)
```

Specifies the blending mode used to apply the tint specified by `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setButtonIconTintList(ColorStateList)`} to the button icon drawable. The default mode is SRC_IN.

ref com.google.android.material.R.styleable#MaterialCheckBox_buttonIconTintMode

| Parameters |
|---|---|
| `Mode tintMode` | the blending mode used to apply the tint |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#getButtonIconTintMode()` |   |

### setButtonTintList

```
public void setButtonTintList(ColorStateList tintList)
```

### setButtonTintMode

```
public void setButtonTintMode(Mode tintMode)
```

### setCenterIfNoTextEnabled

```
public void setCenterIfNoTextEnabled(boolean centerIfNoTextEnabled)
```

Sets whether this `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox` should center the checkbox icon when there is no text. Default is true.

### setChecked

```
public void setChecked(boolean checked)
```

### setCheckedState

```
public void setCheckedState(int checkedState)
```

Sets the `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox.CheckedState` of the checkbox.

| Parameters |
|---|---|
| `int checkedState` | the checked, unchecked, or indeterminate state to be set |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#getCheckedState()` |   |

### setErrorAccessibilityLabel

```
public void setErrorAccessibilityLabel(CharSequence errorAccessibilityLabel)
```

Sets the accessibility label to be used for the error state announcement by screen readers.

ref com.google.android.material.R.styleable#MaterialCheckBox_errorAccessibilityLabel

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence errorAccessibilityLabel` | the error announcement |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setErrorShown(boolean)` |   |
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#getErrorAccessibilityLabel()` |   |

### setErrorAccessibilityLabelResource

```
public void setErrorAccessibilityLabelResource(int resId)
```

Sets the accessibility label to be used for the error state announcement by screen readers.

ref com.google.android.material.R.styleable#MaterialCheckBox_errorAccessibilityLabel

| Parameters |
|---|---|
| `int resId` | resource ID of the error announcement text |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#setErrorShown(boolean)` |   |
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#getErrorAccessibilityLabel()` |   |

### setErrorShown

```
public void setErrorShown(boolean errorShown)
```

Sets whether the checkbox should be on error state. If true, the error color will be applied to the checkbox.

ref com.google.android.material.R.styleable#MaterialCheckBox_errorShown

| Parameters |
|---|---|
| `boolean errorShown` | whether the checkbox should be on error state. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox#isErrorShown()` |   |

### setOnCheckedChangeListener

```
public void setOnCheckedChangeListener(OnCheckedChangeListener listener)
```

### setStateDescription

```
public void setStateDescription(CharSequence stateDescription)
```

### setUseMaterialThemeColors

```
public void setUseMaterialThemeColors(boolean useMaterialThemeColors)
```

Forces the `https://developer.android.com/reference/com/google/android/material/checkbox/MaterialCheckBox` to use colors from a Material Theme. Overrides any specified ButtonTintList. If set to false, sets the tints to null.

### toggle

```
public void toggle()
```

## Protected methods

### onAttachedToWindow

```
protected void onAttachedToWindow()
```

### onCreateDrawableState

```
protected int[] onCreateDrawableState(int extraSpace)
```

### onDraw

```
protected void onDraw(Canvas canvas)
```