# MaterialButton

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

*** ** * ** ***


```
public class MaterialButton implements Shapeable
```

<br />

Known direct subclasses [ExtendedFloatingActionButton](https://developer.android.com/reference/com/google/android/material/floatingactionbutton/ExtendedFloatingActionButton)

|---|---|
| `https://developer.android.com/reference/com/google/android/material/floatingactionbutton/ExtendedFloatingActionButton` | Extended floating action buttons are used for a special type of promoted action. |

*** ** * ** ***

A convenience class for creating a new Material button.

This class supplies updated Material styles for the button in the constructor. The widget will display the correct default Material styles without the use of the style flag.

All attributes from `com.google.android.material.R.styleable#MaterialButton` are supported. Do not use the `android:background` attribute. MaterialButton manages its own background drawable, and setting a new background means `https://developer.android.com/reference/com/google/android/material/button/MaterialButton` can no longer guarantee that the new attributes it introduces will function properly. If the default background is changed, `https://developer.android.com/reference/com/google/android/material/button/MaterialButton` cannot guarantee well-defined behavior.

For filled buttons, this class uses your theme's `?attr/colorPrimary` for the background tint color and `?attr/colorOnPrimary` for the text color. For unfilled buttons, this class uses `?attr/colorPrimary` for the text color and transparent for the background tint.

Add icons to the start, center, or end of this button using the `app:icon`, `
app:iconPadding`, `app:iconTint`, `app:iconTintMode` and `app:iconGravity` attributes.

If a start-aligned icon is added to this button, please use a style like one of the ".Icon" styles specified in the default MaterialButton styles. The ".Icon" styles adjust padding slightly to achieve a better visual balance. This style should only be used with a start-aligned icon button. If your icon is end-aligned, you cannot use a ".Icon" style and must instead manually adjust your padding such that the visual adjustment is mirrored.

Specify background tint using the `app:backgroundTint` and `
app:backgroundTintMode` attributes, which accepts either a color or a color state list.

Ripple color / press state color can be specified using the `app:rippleColor` attribute. Ripple opacity will be determined by the Android framework when available. Otherwise, this color will be overlaid on the button at a 50% opacity when button is pressed.

Set the stroke color using the `app:strokeColor` attribute, which accepts either a color or a color state list. Stroke width can be set using the `app:strokeWidth` attribute.

Specify the radius of all four corners of the button using the `app:cornerRadius` attribute.

For more information, see the [component developer guidance](https://github.com/material-components/material-components-android/blob/master/docs/components/Button.md) and [design guidelines](https://material.io/components/buttons/overview).

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/java/lang/annotation/Retention(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.SOURCE) public annotation https://developer.android.com/reference/com/google/android/material/button/MaterialButton.IconGravity` Positions the icon can be set to. |
| `public interface https://developer.android.com/reference/com/google/android/material/button/MaterialButton.OnCheckedChangeListener` Interface definition for a callback to be invoked when the button checked state changes. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#ICON_GRAVITY_END() = 3` Gravity used to position the icon at the end of the view. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#ICON_GRAVITY_START() = 1` Gravity used to position the icon at the start of the view. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#ICON_GRAVITY_TEXT_END() = 4` Gravity used to position the icon in the center of the view at the end of the text |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#ICON_GRAVITY_TEXT_START() = 2` Gravity used to position the icon in the center of the view at the start of the text |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#ICON_GRAVITY_TEXT_TOP() = 32` Gravity used to position the icon in the center of the view at the top of the text |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#ICON_GRAVITY_TOP() = 16` Gravity used to position the icon at the top of the view. |

| ### Public fields |
|---|---|
| `Drawable` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#icon()` |
| `int` | `@https://developer.android.com/reference/com/google/android/material/button/MaterialButton.IconGravity https://developer.android.com/reference/com/google/android/material/button/MaterialButton#iconGravity()` |
| `int` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#iconPadding()` |
| `int` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#iconSize()` |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#iconTint()` |
| `Mode` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#iconTintMode()` |
| `Drawable` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#secondaryIcon()` |
| `int` | `@https://developer.android.com/reference/com/google/android/material/button/MaterialButton.IconGravity https://developer.android.com/reference/com/google/android/material/button/MaterialButton#secondaryIconGravity()` |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#secondaryIconTint()` |
| `Mode` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#secondaryIconTintMode()` |

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

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#addOnCheckedChangeListener(com.google.android.material.button.MaterialButton.OnCheckedChangeListener)( https://developer.android.com/reference/com/google/android/material/button/MaterialButton.OnCheckedChangeListener listener )` Add a listener that will be invoked when the checked state of this MaterialButton changes. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#clearOnCheckedChangeListeners()()` Remove all previously added `https://developer.android.com/reference/com/google/android/material/button/MaterialButton.OnCheckedChangeListener`s. |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getBackgroundTintList()()` |
| `Mode` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getBackgroundTintMode()()` |
| `int` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getCornerRadius()()` Gets the corner radius for this button. |
| `Drawable` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getIcon()()` Gets the icon shown for this button, if present. |
| `int` | `@https://developer.android.com/reference/com/google/android/material/button/MaterialButton.IconGravity https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getIconGravity()()` Gets the icon gravity for this button |
| `int` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getIconPadding()()` Gets the padding between the button icon and the button text, if icon is present. |
| `int` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getIconSize()()` Returns the size of the icon if it was set. |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getIconTint()()` Gets the tint list for the icon shown for this button. |
| `Mode` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getIconTintMode()()` Gets the tint mode for the icon shown for this button. |
| `int` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getInsetBottom()()` Gets the bottom inset for this button |
| `int` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getInsetLeft()()` Gets the left inset for this button. |
| `int` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getInsetRight()()` Gets the right inset for this button. |
| `int` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getInsetTop()()` Gets the top inset for this button |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getRippleColor()()` Gets the ripple color for this button. |
| `Drawable` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getSecondaryIcon()()` Gets the secondary icon for this button, if present. |
| `int` | `@https://developer.android.com/reference/com/google/android/material/button/MaterialButton.IconGravity https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getSecondaryIconGravity()()` Gets the secondary icon's gravity for this button. |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getSecondaryIconTint()()` Gets the tint list for the secondary icon shown for this button. |
| `Mode` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getSecondaryIconTintMode()()` Gets the tint mode for the secondary icon shown for this button. |
| `https://developer.android.com/reference/com/google/android/material/shape/ShapeAppearanceModel` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getShapeAppearanceModel()()` Returns the `https://developer.android.com/reference/com/google/android/material/shape/ShapeAppearanceModel` used for this `https://developer.android.com/reference/com/google/android/material/button/MaterialButton`'s original drawables. |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getStrokeColor()()` Gets the stroke color for this button. |
| `int` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getStrokeWidth()()` Gets the stroke width for this button. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#isCheckable()()` Returns whether this MaterialButton is checkable. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#isChecked()()` |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#isOpticalCenterEnabled()()` Returns whether the optical center feature is enabled. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#isToggleCheckedStateOnClick()()` Returns whether or not clicking the button will toggle the checked state. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#onInitializeAccessibilityEvent(AccessibilityEvent)(AccessibilityEvent accessibilityEvent)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)(AccessibilityNodeInfo info)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#onRestoreInstanceState(Parcelable)(Parcelable state)` |
| `Parcelable` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#onSaveInstanceState()()` |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#performClick()()` |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#refreshDrawableState()()` |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#removeOnCheckedChangeListener(com.google.android.material.button.MaterialButton.OnCheckedChangeListener)( https://developer.android.com/reference/com/google/android/material/button/MaterialButton.OnCheckedChangeListener listener )` Remove a listener that was previously added via `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#addOnCheckedChangeListener(com.google.android.material.button.MaterialButton.OnCheckedChangeListener)`. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setA11yClassName(java.lang.String)(https://developer.android.com/reference/java/lang/String className)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setBackground(Drawable)(Drawable background)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setBackgroundColor(int)(int color)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setBackgroundDrawable(Drawable)(Drawable background)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setBackgroundResource(int)(int backgroundResourceId)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setBackgroundTintList(ColorStateList)(ColorStateList tintList)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setBackgroundTintMode(Mode)(Mode tintMode)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setCheckable(boolean)(boolean checkable)` Sets whether this MaterialButton is checkable. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setChecked(boolean)(boolean checked)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setCompoundDrawablePadding(int)(int padding)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setCornerRadius(int)(int cornerRadius)` Sets the corner radius for this button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setCornerRadiusResource(int)(int cornerRadiusResourceId)` Sets the corner radius dimension resource for this button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setElevation(float)(float elevation)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIcon(Drawable)(Drawable icon)` Sets the icon to show for this button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIconGravity(int)(@https://developer.android.com/reference/com/google/android/material/button/MaterialButton.IconGravity int iconGravity)` Sets the icon gravity for this button |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIconPadding(int)(int iconPadding)` Sets the padding between the button icon and the button text, if icon is present. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIconResource(int)(int iconResourceId)` Sets the icon drawable resource to show for this button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIconSize(int)(int iconSize)` Sets the width and height of the icon. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIconTint(ColorStateList)(ColorStateList iconTint)` Sets the tint list for the icon shown for this button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIconTintMode(Mode)(Mode iconTintMode)` Sets the tint mode for the icon shown for this button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIconTintResource(int)(int iconTintResourceId)` Sets the tint list color resource for the icon shown for this button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setInsetBottom(int)(int insetBottom)` Sets the button bottom inset |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setInsetLeft(int)(int insetLeft)` Sets the button left inset. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setInsetRight(int)(int insetRight)` Sets the button right inset. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setInsetTop(int)(int insetTop)` Sets the button top inset |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setOpticalCenterEnabled(boolean)(boolean opticalCenterEnabled)` Sets whether to enable the optical center feature. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setPressed(boolean)(boolean pressed)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setRippleColor(ColorStateList)(ColorStateList rippleColor)` Sets the ripple color for this button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setRippleColorResource(int)(int rippleColorResourceId)` Sets the ripple color resource for this button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setSecondaryIcon(Drawable)(Drawable icon)` Sets the secondary icon to show for this button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setSecondaryIconGravity(int)( @https://developer.android.com/reference/com/google/android/material/button/MaterialButton.IconGravity int secondaryIconGravity )` Sets the secondary icon's gravity for this button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setSecondaryIconResource(int)(int iconResourceId)` Sets the secondary icon to show for this button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setSecondaryIconTint(ColorStateList)(ColorStateList secondaryIconTint)` Sets the tint list for the secondary icon shown for this button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setSecondaryIconTintMode(Mode)(Mode secondaryIconTintMode)` Sets the tint mode for the secondary icon shown for this button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setSecondaryIconTintResource(int)(int iconTintResourceId)` Sets the tint list color resource for the secondsary icon shown for this button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setShapeAppearanceModel(com.google.android.material.shape.ShapeAppearanceModel)(https://developer.android.com/reference/com/google/android/material/shape/ShapeAppearanceModel shapeAppearanceModel)` Sets the `https://developer.android.com/reference/com/google/android/material/shape/ShapeAppearanceModel` used for this `https://developer.android.com/reference/com/google/android/material/button/MaterialButton`'s original drawables. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setStrokeColor(ColorStateList)(ColorStateList strokeColor)` Sets the stroke color for this button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setStrokeColorResource(int)(int strokeColorResourceId)` Sets the stroke color resource for this button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setStrokeWidth(int)(int strokeWidth)` Sets the stroke width for this button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setStrokeWidthResource(int)(int strokeWidthResourceId)` Sets the stroke width dimension resource for this button. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setText(java.lang.CharSequence,BufferType)(https://developer.android.com/reference/java/lang/CharSequence text, BufferType type)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setTextAlignment(int)(int textAlignment)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setTextAppearance(Context,int)(Context context, int resId)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setTextSize(int,float)(int unit, float size)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setToggleCheckedStateOnClick(boolean)(boolean toggleCheckedStateOnClick)` Sets whether or not to toggle the button checked state on click. |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setWidth(int)(int pixels)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#toggle()()` |

| ### Protected methods |
|---|---|
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#onAttachedToWindow()()` |
| `int[]` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#onCreateDrawableState(int)(int extraSpace)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#onLayout(boolean,int,int,int,int)(boolean changed, int left, int top, int right, int bottom)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#onTextChanged(java.lang.CharSequence,int,int,int)(https://developer.android.com/reference/java/lang/CharSequence charSequence, int i, int i1, int i2)` |

## Constants

### ICON_GRAVITY_END

```
public static final int ICON_GRAVITY_END = 3
```

Gravity used to position the icon at the end of the view.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIconGravity(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getIconGravity()` |   |

### ICON_GRAVITY_START

```
public static final int ICON_GRAVITY_START = 1
```

Gravity used to position the icon at the start of the view.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIconGravity(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getIconGravity()` |   |

### ICON_GRAVITY_TEXT_END

```
public static final int ICON_GRAVITY_TEXT_END = 4
```

Gravity used to position the icon in the center of the view at the end of the text

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIconGravity(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getIconGravity()` |   |

### ICON_GRAVITY_TEXT_START

```
public static final int ICON_GRAVITY_TEXT_START = 2
```

Gravity used to position the icon in the center of the view at the start of the text

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIconGravity(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getIconGravity()` |   |

### ICON_GRAVITY_TEXT_TOP

```
public static final int ICON_GRAVITY_TEXT_TOP = 32
```

Gravity used to position the icon in the center of the view at the top of the text

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIconGravity(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getIconGravity()` |   |

### ICON_GRAVITY_TOP

```
public static final int ICON_GRAVITY_TOP = 16
```

Gravity used to position the icon at the top of the view.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIconGravity(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getIconGravity()` |   |

## Public fields

### icon

```
public Drawable icon
```

### iconGravity

```
@MaterialButton.IconGravity
public int iconGravity
```

### iconPadding

```
public int iconPadding
```

### iconSize

```
public int iconSize
```

### iconTint

```
public ColorStateList iconTint
```

### iconTintMode

```
public Mode iconTintMode
```

### secondaryIcon

```
public Drawable secondaryIcon
```

### secondaryIconGravity

```
@MaterialButton.IconGravity
public int secondaryIconGravity
```

### secondaryIconTint

```
public ColorStateList secondaryIconTint
```

### secondaryIconTintMode

```
public Mode secondaryIconTintMode
```

## Public constructors

### MaterialButton

```
public MaterialButton(Context context)
```

### MaterialButton

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

### MaterialButton

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

## Public methods

### addOnCheckedChangeListener

```
public void addOnCheckedChangeListener(
    MaterialButton.OnCheckedChangeListener listener
)
```

Add a listener that will be invoked when the checked state of this MaterialButton changes. See `https://developer.android.com/reference/com/google/android/material/button/MaterialButton.OnCheckedChangeListener`.

Components that add a listener should take care to remove it when finished via `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#removeOnCheckedChangeListener(com.google.android.material.button.MaterialButton.OnCheckedChangeListener)`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton.OnCheckedChangeListener listener` | listener to add |

### clearOnCheckedChangeListeners

```
public void clearOnCheckedChangeListeners()
```

Remove all previously added `https://developer.android.com/reference/com/google/android/material/button/MaterialButton.OnCheckedChangeListener`s.

### getBackgroundTintList

```
public ColorStateList getBackgroundTintList()
```

### getBackgroundTintMode

```
public Mode getBackgroundTintMode()
```

### getCornerRadius

```
public int getCornerRadius()
```

Gets the corner radius for this button.

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

| Returns |
|---|---|
| `int` | Corner radius for this button. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setCornerRadius(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setCornerRadiusResource(int)` |   |

### getIcon

```
public Drawable getIcon()
```

Gets the icon shown for this button, if present.

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

| Returns |
|---|---|
| `Drawable` | Icon shown for this button, if present. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIcon(Drawable)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIconResource(int)` |   |

### getIconGravity

```
@MaterialButton.IconGravity
public int getIconGravity()
```

Gets the icon gravity for this button

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

| Returns |
|---|---|
| `int` | Icon gravity of the button. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIconGravity(int)` |   |

### getIconPadding

```
public int getIconPadding()
```

Gets the padding between the button icon and the button text, if icon is present.

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

| Returns |
|---|---|
| `int` | Padding between the button icon and the button text, if icon is present. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIconPadding(int)` |   |

### getIconSize

```
public int getIconSize()
```

Returns the size of the icon if it was set.

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

| Returns |
|---|---|
| `int` | Returns the size of the icon if it was set in pixels, 0 otherwise. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIconSize(int)` |   |

### getIconTint

```
public ColorStateList getIconTint()
```

Gets the tint list for the icon shown for this button.

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

| Returns |
|---|---|
| `ColorStateList` | Tint list for the icon shown for this button. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIconTint(ColorStateList)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIconTintResource(int)` |   |

### getIconTintMode

```
public Mode getIconTintMode()
```

Gets the tint mode for the icon shown for this button.

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

| Returns |
|---|---|
| `Mode` | Tint mode for the icon shown for this button. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIconTintMode(Mode)` |   |

### getInsetBottom

```
public int getInsetBottom()
```

Gets the bottom inset for this button

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

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setInsetBottom(int)` |   |

### getInsetLeft

```
public int getInsetLeft()
```

Gets the left inset for this button.

This acts like the start inset in RTL layouts. It's using the "left" naming convention instead of "start" to be consistent with the android:insetLeft attribute.

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

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setInsetLeft(int)` |   |

### getInsetRight

```
public int getInsetRight()
```

Gets the right inset for this button.

This acts like the end inset in RTL layouts. It's using the "right" naming convention instead of "end" to be consistent with the android:insetRight attribute.

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

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setInsetRight(int)` |   |

### getInsetTop

```
public int getInsetTop()
```

Gets the top inset for this button

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

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setInsetTop(int)` |   |

### getRippleColor

```
public ColorStateList getRippleColor()
```

Gets the ripple color for this button.

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

| Returns |
|---|---|
| `ColorStateList` | The color used for the ripple. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setRippleColor(ColorStateList)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setRippleColorResource(int)` |   |

### getSecondaryIcon

```
public Drawable getSecondaryIcon()
```

Gets the secondary icon for this button, if present.

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

| Returns |
|---|---|
| `Drawable` | Secondary icon for this button, if present. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setSecondaryIcon(Drawable)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setSecondaryIconResource(int)` |   |

### getSecondaryIconGravity

```
@MaterialButton.IconGravity
public int getSecondaryIconGravity()
```

Gets the secondary icon's gravity for this button.

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

| Returns |
|---|---|
| `int` | Icon gravity of the secondary icon. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIconGravity(int)` |   |

### getSecondaryIconTint

```
public ColorStateList getSecondaryIconTint()
```

Gets the tint list for the secondary icon shown for this button.

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

| Returns |
|---|---|
| `ColorStateList` | Tint list for the secondary icon shown for this button. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setSecondaryIconTint(ColorStateList)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setSecondaryIconTintResource(int)` |   |

### getSecondaryIconTintMode

```
public Mode getSecondaryIconTintMode()
```

Gets the tint mode for the secondary icon shown for this button.

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

| Returns |
|---|---|
| `Mode` | Tint mode for the secondary icon shown for this button. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setSecondaryIconTintMode(Mode)` |   |

### getShapeAppearanceModel

```
public ShapeAppearanceModel getShapeAppearanceModel()
```

Returns the `https://developer.android.com/reference/com/google/android/material/shape/ShapeAppearanceModel` used for this `https://developer.android.com/reference/com/google/android/material/button/MaterialButton`'s original drawables.

This `https://developer.android.com/reference/com/google/android/material/shape/ShapeAppearanceModel` can be modified to change the component's shape.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the MaterialButton's background has been overwritten. |

### getStrokeColor

```
public ColorStateList getStrokeColor()
```

Gets the stroke color for this button.

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

| Returns |
|---|---|
| `ColorStateList` | The color used for the stroke. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setStrokeColor(ColorStateList)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setStrokeColorResource(int)` |   |

### getStrokeWidth

```
public int getStrokeWidth()
```

Gets the stroke width for this button.

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

| Returns |
|---|---|
| `int` | Stroke width for this button. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setStrokeWidth(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setStrokeWidthResource(int)` |   |

### isCheckable

```
public boolean isCheckable()
```

Returns whether this MaterialButton is checkable.

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

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setCheckable(boolean)` |   |

### isChecked

```
public boolean isChecked()
```

### isOpticalCenterEnabled

```
public boolean isOpticalCenterEnabled()
```

Returns whether the optical center feature is enabled.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setOpticalCenterEnabled(boolean)` |   |

### isToggleCheckedStateOnClick

```
public boolean isToggleCheckedStateOnClick()
```

Returns whether or not clicking the button will toggle the checked state.

ref R.styleable#toggleCheckedStateOnClick

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setToggleCheckedStateOnClick(boolean)` |   |

### onInitializeAccessibilityEvent

```
public void onInitializeAccessibilityEvent(AccessibilityEvent accessibilityEvent)
```

### onInitializeAccessibilityNodeInfo

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

### onRestoreInstanceState

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

### onSaveInstanceState

```
public Parcelable onSaveInstanceState()
```

### performClick

```
public boolean performClick()
```

### refreshDrawableState

```
public void refreshDrawableState()
```

### removeOnCheckedChangeListener

```
public void removeOnCheckedChangeListener(
    MaterialButton.OnCheckedChangeListener listener
)
```

Remove a listener that was previously added via `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#addOnCheckedChangeListener(com.google.android.material.button.MaterialButton.OnCheckedChangeListener)`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton.OnCheckedChangeListener listener` | listener to remove |

### setA11yClassName

```
public void setA11yClassName(String className)
```

### setBackground

```
public void setBackground(Drawable background)
```

### setBackgroundColor

```
public void setBackgroundColor(int color)
```

### setBackgroundDrawable

```
public void setBackgroundDrawable(Drawable background)
```

### setBackgroundResource

```
public void setBackgroundResource(int backgroundResourceId)
```

### setBackgroundTintList

```
public void setBackgroundTintList(ColorStateList tintList)
```

### setBackgroundTintMode

```
public void setBackgroundTintMode(Mode tintMode)
```

### setCheckable

```
public void setCheckable(boolean checkable)
```

Sets whether this MaterialButton is checkable.

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

| Parameters |
|---|---|
| `boolean checkable` | Whether this button is checkable. |

### setChecked

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

### setCompoundDrawablePadding

```
public void setCompoundDrawablePadding(int padding)
```

### setCornerRadius

```
public void setCornerRadius(int cornerRadius)
```

Sets the corner radius for this button.

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

| Parameters |
|---|---|
| `int cornerRadius` | Corner radius for this button. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setCornerRadiusResource(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getCornerRadius()` |   |

### setCornerRadiusResource

```
public void setCornerRadiusResource(int cornerRadiusResourceId)
```

Sets the corner radius dimension resource for this button.

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

| Parameters |
|---|---|
| `int cornerRadiusResourceId` | Corner radius dimension resource for this button. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setCornerRadius(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getCornerRadius()` |   |

### setElevation

```
public void setElevation(float elevation)
```

### setIcon

```
public void setIcon(Drawable icon)
```

Sets the icon to show for this button. By default, this icon will be shown on the left side of the button.

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

| Parameters |
|---|---|
| `Drawable icon` | Drawable to use for the button's icon. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIconResource(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getIcon()` |   |

### setIconGravity

```
public void setIconGravity(@MaterialButton.IconGravity int iconGravity)
```

Sets the icon gravity for this button

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/com/google/android/material/button/MaterialButton.IconGravity int iconGravity` | icon gravity for this button |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getIconGravity()` |   |

### setIconPadding

```
public void setIconPadding(int iconPadding)
```

Sets the padding between the button icon and the button text, if icon is present.

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

| Parameters |
|---|---|
| `int iconPadding` | Padding between the button icon and the button text, if icon is present. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getIconPadding()` |   |

### setIconResource

```
public void setIconResource(int iconResourceId)
```

Sets the icon drawable resource to show for this button. By default, this icon will be shown on the left side of the button.

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

| Parameters |
|---|---|
| `int iconResourceId` | Drawable resource ID to use for the button's icon. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIcon(Drawable)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getIcon()` |   |

### setIconSize

```
public void setIconSize(int iconSize)
```

Sets the width and height of the icon. Use 0 to use source Drawable size.

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

| Parameters |
|---|---|
| `int iconSize` | new dimension for width and height of the icon in pixels. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getIconSize()` |   |

### setIconTint

```
public void setIconTint(ColorStateList iconTint)
```

Sets the tint list for the icon shown for this button.

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

| Parameters |
|---|---|
| `ColorStateList iconTint` | Tint list for the icon shown for this button. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIconTintResource(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getIconTint()` |   |

### setIconTintMode

```
public void setIconTintMode(Mode iconTintMode)
```

Sets the tint mode for the icon shown for this button.

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

| Parameters |
|---|---|
| `Mode iconTintMode` | Tint mode for the icon shown for this button. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getIconTintMode()` |   |

### setIconTintResource

```
public void setIconTintResource(int iconTintResourceId)
```

Sets the tint list color resource for the icon shown for this button.

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

| Parameters |
|---|---|
| `int iconTintResourceId` | Tint list color resource for the icon shown for this button. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setIconTint(ColorStateList)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getIconTint()` |   |

### setInsetBottom

```
public void setInsetBottom(int insetBottom)
```

Sets the button bottom inset

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

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getInsetBottom()` |   |

### setInsetLeft

```
public void setInsetLeft(int insetLeft)
```

Sets the button left inset.

This acts like the start inset in RTL layouts. It's using the "left" naming convention instead of "start" to be consistent with the android:insetLeft attribute.

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

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getInsetLeft()` |   |

### setInsetRight

```
public void setInsetRight(int insetRight)
```

Sets the button right inset.

This acts like the end inset in RTL layouts. It's using the "right" naming convention instead of "end" to be consistent with the inset to be consistent with the android:insetRight attribute.

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

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getInsetRight()` |   |

### setInsetTop

```
public void setInsetTop(int insetTop)
```

Sets the button top inset

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

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getInsetTop()` |   |

### setOpticalCenterEnabled

```
public void setOpticalCenterEnabled(boolean opticalCenterEnabled)
```

Sets whether to enable the optical center feature.

| Parameters |
|---|---|
| `boolean opticalCenterEnabled` | whether to enable optical centering. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#isOpticalCenterEnabled()` |   |

### setPressed

```
public void setPressed(boolean pressed)
```

### setRippleColor

```
public void setRippleColor(ColorStateList rippleColor)
```

Sets the ripple color for this button.

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

| Parameters |
|---|---|
| `ColorStateList rippleColor` | Color to use for the ripple. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setRippleColorResource(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getRippleColor()` |   |

### setRippleColorResource

```
public void setRippleColorResource(int rippleColorResourceId)
```

Sets the ripple color resource for this button.

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

| Parameters |
|---|---|
| `int rippleColorResourceId` | Color resource to use for the ripple. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setRippleColor(ColorStateList)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getRippleColor()` |   |

### setSecondaryIcon

```
public void setSecondaryIcon(Drawable icon)
```

Sets the secondary icon to show for this button. By default, this icon will be shown on the end of the button. A secondary icon used in addition with another icon should be generally avoided, as it is meant for a pointer optimized UI such as of a laptop UI.

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

| Parameters |
|---|---|
| `Drawable icon` | Drawable to use for the secondary icon. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setSecondaryIconResource(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getSecondaryIcon()` |   |

### setSecondaryIconGravity

```
public void setSecondaryIconGravity(
    @MaterialButton.IconGravity int secondaryIconGravity
)
```

Sets the secondary icon's gravity for this button.

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/com/google/android/material/button/MaterialButton.IconGravity int secondaryIconGravity` | secondary icon gravity for this button |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getIconGravity()` |   |

### setSecondaryIconResource

```
public void setSecondaryIconResource(int iconResourceId)
```

Sets the secondary icon to show for this button. By default, this icon will be shown on the end of the button. A secondary icon used in addition with another icon should be generally avoided, as it is meant for a pointer optimized UI such as of a laptop UI.

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

| Parameters |
|---|---|
| `int iconResourceId` | Drawable resource ID to use for the secondary icon. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setSecondaryIcon(Drawable)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getSecondaryIcon()` |   |

### setSecondaryIconTint

```
public void setSecondaryIconTint(ColorStateList secondaryIconTint)
```

Sets the tint list for the secondary icon shown for this button.

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

| Parameters |
|---|---|
| `ColorStateList secondaryIconTint` | Tint list for the secondary icon shown for this button. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setSecondaryIconTintResource(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getSecondaryIconTint()` |   |

### setSecondaryIconTintMode

```
public void setSecondaryIconTintMode(Mode secondaryIconTintMode)
```

Sets the tint mode for the secondary icon shown for this button.

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

| Parameters |
|---|---|
| `Mode secondaryIconTintMode` | Tint mode for the secondary icon shown for this button. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getSecondaryIconTintMode()` |   |

### setSecondaryIconTintResource

```
public void setSecondaryIconTintResource(int iconTintResourceId)
```

Sets the tint list color resource for the secondsary icon shown for this button.

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

| Parameters |
|---|---|
| `int iconTintResourceId` | Tint list color resource for the secondary icon shown for this button |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setSecondaryIconTint(ColorStateList)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getSecondaryIconTint()` |   |

### setShapeAppearanceModel

```
public void setShapeAppearanceModel(ShapeAppearanceModel shapeAppearanceModel)
```

Sets the `https://developer.android.com/reference/com/google/android/material/shape/ShapeAppearanceModel` used for this `https://developer.android.com/reference/com/google/android/material/button/MaterialButton`'s original drawables.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the MaterialButton's background has been overwritten. |

### setStrokeColor

```
public void setStrokeColor(ColorStateList strokeColor)
```

Sets the stroke color for this button. Both stroke color and stroke width must be set for a stroke to be drawn.

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

| Parameters |
|---|---|
| `ColorStateList strokeColor` | Color to use for the stroke. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setStrokeColorResource(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getStrokeColor()` |   |

### setStrokeColorResource

```
public void setStrokeColorResource(int strokeColorResourceId)
```

Sets the stroke color resource for this button. Both stroke color and stroke width must be set for a stroke to be drawn.

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

| Parameters |
|---|---|
| `int strokeColorResourceId` | Color resource to use for the stroke. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setStrokeColor(ColorStateList)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getStrokeColor()` |   |

### setStrokeWidth

```
public void setStrokeWidth(int strokeWidth)
```

Sets the stroke width for this button. Both stroke color and stroke width must be set for a stroke to be drawn.

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

| Parameters |
|---|---|
| `int strokeWidth` | Stroke width for this button. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setStrokeWidthResource(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getStrokeWidth()` |   |

### setStrokeWidthResource

```
public void setStrokeWidthResource(int strokeWidthResourceId)
```

Sets the stroke width dimension resource for this button. Both stroke color and stroke width must be set for a stroke to be drawn.

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

| Parameters |
|---|---|
| `int strokeWidthResourceId` | Stroke width dimension resource for this button. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#setStrokeWidth(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/button/MaterialButton#getStrokeWidth()` |   |

### setText

```
public void setText(CharSequence text, BufferType type)
```

### setTextAlignment

```
public void setTextAlignment(int textAlignment)
```

### setTextAppearance

```
public void setTextAppearance(Context context, int resId)
```

### setTextSize

```
public void setTextSize(int unit, float size)
```

### setToggleCheckedStateOnClick

```
public void setToggleCheckedStateOnClick(boolean toggleCheckedStateOnClick)
```

Sets whether or not to toggle the button checked state on click.

ref R.styleable#toggleCheckedStateOnClick

| Parameters |
|---|---|
| `boolean toggleCheckedStateOnClick` | whether or not to toggle the checked state on click. |

### setWidth

```
public void setWidth(int pixels)
```

### toggle

```
public void toggle()
```

## Protected methods

### onAttachedToWindow

```
protected void onAttachedToWindow()
```

### onCreateDrawableState

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

### onLayout

```
protected void onLayout(boolean changed, int left, int top, int right, int bottom)
```

### onTextChanged

```
protected void onTextChanged(CharSequence charSequence, int i, int i1, int i2)
```