# CompoundButtonCompat

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/widget/CompoundButtonCompat.java+class:androidx.core.widget.CompoundButtonCompat) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

*** ** * ** ***


```
public final class CompoundButtonCompat
```

<br />

*** ** * ** ***

Helper for accessing `https://developer.android.com/reference/android/widget/CompoundButton.html`.

## Summary

| ### Public methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | `https://developer.android.com/reference/androidx/core/widget/CompoundButtonCompat#getButtonDrawable(android.widget.CompoundButton)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/widget/CompoundButton.html button)` Returns the drawable used as the compound button image |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/content/res/ColorStateList.html` | `https://developer.android.com/reference/androidx/core/widget/CompoundButtonCompat#getButtonTintList(android.widget.CompoundButton)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/widget/CompoundButton.html button)` Returns the tint applied to the button drawable |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/PorterDuff.Mode.html` | `https://developer.android.com/reference/androidx/core/widget/CompoundButtonCompat#getButtonTintMode(android.widget.CompoundButton)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/widget/CompoundButton.html button)` name android:buttonTintMode |
| `static void` | `https://developer.android.com/reference/androidx/core/widget/CompoundButtonCompat#setButtonTintList(android.widget.CompoundButton,android.content.res.ColorStateList)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/widget/CompoundButton.html button, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/content/res/ColorStateList.html tint )` Applies a tint to the button drawable. |
| `static void` | `https://developer.android.com/reference/androidx/core/widget/CompoundButtonCompat#setButtonTintMode(android.widget.CompoundButton,android.graphics.PorterDuff.Mode)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/widget/CompoundButton.html button, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/PorterDuff.Mode.html tintMode )` Specifies the blending mode used to apply the tint specified by `https://developer.android.com/reference/androidx/core/widget/CompoundButtonCompat#setButtonTintList(android.widget.CompoundButton,android.content.res.ColorStateList)`} to the button drawable. |

## Public methods

### getButtonDrawable

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static @Nullable Drawable getButtonDrawable(@NonNull CompoundButton button)
```

Returns the drawable used as the compound button image

| See also |
|---|---|
| `https://developer.android.com/reference/android/widget/CompoundButton.html#setButtonDrawable(android.graphics.drawable.Drawable)` |   |

### getButtonTintList

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static @Nullable ColorStateList getButtonTintList(@NonNull CompoundButton button)
```

Returns the tint applied to the button drawable

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/widget/CompoundButtonCompat#setButtonTintList(android.widget.CompoundButton,android.content.res.ColorStateList)` |   |

### getButtonTintMode

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static @Nullable PorterDuff.Mode getButtonTintMode(@NonNull CompoundButton button)
```

name android:buttonTintMode

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/PorterDuff.Mode.html` | the blending mode used to apply the tint to the button drawable |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/widget/CompoundButtonCompat#setButtonTintMode(android.widget.CompoundButton,android.graphics.PorterDuff.Mode)` |   |

### setButtonTintList

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static void setButtonTintList(
    @NonNull CompoundButton button,
    @Nullable ColorStateList tint
)
```

Applies a tint to the button drawable. Does not modify the current tint mode, which is `https://developer.android.com/reference/android/graphics/PorterDuff.Mode.html#SRC_IN` by default.

Subsequent calls to `https://developer.android.com/reference/android/widget/CompoundButton.html#setButtonDrawable(android.graphics.drawable.Drawable)` should automatically mutate the drawable and apply the specified tint and tint mode using `https://developer.android.com/reference/androidx/core/graphics/drawable/DrawableCompat#setTintList(android.graphics.drawable.Drawable,android.content.res.ColorStateList)`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/widget/CompoundButton.html button` | button for which to apply the tint. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/content/res/ColorStateList.html tint` | the tint to apply, may be `null` to clear tint |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/widget/CompoundButtonCompat#setButtonTintList(android.widget.CompoundButton,android.content.res.ColorStateList)` |   |

### setButtonTintMode

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
public static void setButtonTintMode(
    @NonNull CompoundButton button,
    @Nullable PorterDuff.Mode tintMode
)
```

Specifies the blending mode used to apply the tint specified by `https://developer.android.com/reference/androidx/core/widget/CompoundButtonCompat#setButtonTintList(android.widget.CompoundButton,android.content.res.ColorStateList)`} to the button drawable. The default mode is `https://developer.android.com/reference/android/graphics/PorterDuff.Mode.html#SRC_IN`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/widget/CompoundButton.html button` | button for which to apply the tint mode. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/PorterDuff.Mode.html tintMode` | the blending mode used to apply the tint, may be `null` to clear tint |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/widget/CompoundButtonCompat#getButtonTintMode(android.widget.CompoundButton)` |   |
| `https://developer.android.com/reference/androidx/core/graphics/drawable/DrawableCompat#setTintMode(android.graphics.drawable.Drawable,android.graphics.PorterDuff.Mode)` |   |