MaterialCheckBox

public class MaterialCheckBox
extends AppCompatCheckBox

java.lang.Object
   ↳ android.view.View
     ↳ android.widget.TextView
       ↳ android.widget.Button
         ↳ android.widget.CompoundButton
           ↳ android.widget.CheckBox
             ↳ androidx.appcompat.widget.AppCompatCheckBox
               ↳ com.google.android.material.checkbox.MaterialCheckBox


A class that creates a Material Themed CheckBox.

This class uses attributes from the Material Theme to style a CheckBox. Excepting color changes, it behaves identically to AppCompatCheckBox. Your theme's ?attr/colorControlActivated, ?attr/colorSurface, and ?attr/colorOnSurface must be set.

Summary

Inherited constants

Inherited fields

Public constructors

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

Public methods

boolean isCenterIfNoTextEnabled()

Returns true if this MaterialCheckBox will center the checkbox icon when there is no text.

boolean isUseMaterialThemeColors()

Returns true if this MaterialCheckBox defaults to colors from a Material Theme.

void setCenterIfNoTextEnabled(boolean centerIfNoTextEnabled)

Sets whether this MaterialCheckBox should center the checkbox icon when there is no text.

void setUseMaterialThemeColors(boolean useMaterialThemeColors)

Forces the MaterialCheckBox to use colors from a Material Theme.

Protected methods

void onAttachedToWindow()
void onDraw(Canvas canvas)

Inherited methods

Public constructors

MaterialCheckBox

public MaterialCheckBox (Context context)

Parameters
context Context

MaterialCheckBox

public MaterialCheckBox (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

MaterialCheckBox

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

Parameters
context Context

attrs AttributeSet

defStyleAttr int

Public methods

isCenterIfNoTextEnabled

public boolean isCenterIfNoTextEnabled ()

Returns true if this MaterialCheckBox will center the checkbox icon when there is no text.

Returns
boolean

isUseMaterialThemeColors

public boolean isUseMaterialThemeColors ()

Returns true if this MaterialCheckBox defaults to colors from a Material Theme.

Returns
boolean

setCenterIfNoTextEnabled

public void setCenterIfNoTextEnabled (boolean centerIfNoTextEnabled)

Sets whether this MaterialCheckBox should center the checkbox icon when there is no text. Default is true.

Parameters
centerIfNoTextEnabled boolean

setUseMaterialThemeColors

public void setUseMaterialThemeColors (boolean useMaterialThemeColors)

Forces the MaterialCheckBox to use colors from a Material Theme. Overrides any specified ButtonTintList. If set to false, sets the tints to null. Use AppCompatCheckBox.setSupportButtonTintList(ColorStateList) to change button tints.

Parameters
useMaterialThemeColors boolean

Protected methods

onAttachedToWindow

protected void onAttachedToWindow ()

onDraw

protected void onDraw (Canvas canvas)

Parameters
canvas Canvas