# Button.Builder

Artifact: [androidx.wear.protolayout:protolayout-material](https://developer.android.com/jetpack/androidx/releases/wear-protolayout) [View Source](https://cs.android.com/search?q=file:androidx/wear/protolayout/material/Button.java+class:androidx.wear.protolayout.material.Button.Builder) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

*** ** * ** ***


```
public final class Button.Builder
```

<br />

*** ** * ** ***

Builder class for `https://developer.android.com/reference/androidx/wear/protolayout/material/Button`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder#Builder(android.content.Context,androidx.wear.protolayout.ModifiersBuilders.Clickable)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/ModifiersBuilders.Clickable clickable )` Creates a builder for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Button` from the given content. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Button` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder#build()()` Constructs and returns `https://developer.android.com/reference/androidx/wear/protolayout/material/Button` with the provided field and look. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder#setButtonColors(androidx.wear.protolayout.material.ButtonColors)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/ButtonColors buttonColors)` Sets the colors for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Button`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder#setContentDescription(java.lang.CharSequence)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html contentDescription)` Sets the static content description for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Button`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder#setContentDescription(androidx.wear.protolayout.TypeBuilders.StringProp)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/TypeBuilders.StringProp contentDescription )` Sets the content description for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Button`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder#setCustomContent(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement content)` Sets the custom content for this Button. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder#setIconContent(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html imageResourceId)` Sets the content of this Button to be the given icon with the default size that is half of the set size of the button. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder#setIconContent(java.lang.String,androidx.wear.protolayout.DimensionBuilders.DpProp)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html imageResourceId, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/DimensionBuilders.DpProp size )` Sets the content of this Button to be the given icon with the given size. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder#setImageContent(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html imageResourceId)` Sets the content of this Button to be the given image, i.e. contacts photo. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder#setSize(androidx.wear.protolayout.DimensionBuilders.DpProp)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/DimensionBuilders.DpProp size)` Sets the size for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Button`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder#setSize(float)(@https://developer.android.com/reference/androidx/annotation/Dimension(unit = 0) float size)` Sets the size for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Button`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder#setTextContent(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html text)` Sets the content of this Button to be the given text with the default font for the set size (for the `https://developer.android.com/reference/androidx/wear/protolayout/material/ButtonDefaults#DEFAULT_SIZE()`, `https://developer.android.com/reference/androidx/wear/protolayout/material/ButtonDefaults#LARGE_SIZE()` and `https://developer.android.com/reference/androidx/wear/protolayout/material/ButtonDefaults#EXTRA_LARGE_SIZE()` is `https://developer.android.com/reference/androidx/wear/protolayout/material/Typography#TYPOGRAPHY_TITLE2()`, `https://developer.android.com/reference/androidx/wear/protolayout/material/Typography#TYPOGRAPHY_TITLE1()` and `https://developer.android.com/reference/androidx/wear/protolayout/material/Typography#TYPOGRAPHY_DISPLAY3()` respectively). |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder#setTextContent(java.lang.String,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html text, int typographyName)` Sets the content of this Button to be the given text with the given font. |

## Public constructors

### Builder

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
public Builder(
    @NonNull Context context,
    @NonNull ModifiersBuilders.Clickable clickable
)
```

Creates a builder for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Button` from the given content. Custom content should be later set with one of the following `https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder#setIconContent(java.lang.String)`, `https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder#setIconContent(java.lang.String,androidx.wear.protolayout.DimensionBuilders.DpProp)`, `https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder#setTextContent(java.lang.String)`, `https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder#setTextContent(java.lang.String,int)` or `https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder#setImageContent(java.lang.String)`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | The application's context. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/ModifiersBuilders.Clickable clickable` | Associated `https://developer.android.com/reference/androidx/wear/protolayout/ModifiersBuilders.Clickable` for click events. When the Button is clicked it will fire the associated action. |

## Public methods

### build

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
public @NonNull Button build()
```

Constructs and returns `https://developer.android.com/reference/androidx/wear/protolayout/material/Button` with the provided field and look.

### setButtonColors

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
public @NonNull Button.Builder setButtonColors(@NonNull ButtonColors buttonColors)
```

Sets the colors for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Button`. If not set, `https://developer.android.com/reference/androidx/wear/protolayout/material/ButtonDefaults#PRIMARY_COLORS()` will be used.

Note: The content color will be ignored (and won't be returned by the getter) if the Button content is an image.

### setContentDescription

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
public @NonNull Button.Builder setContentDescription(@NonNull CharSequence contentDescription)
```

Sets the static content description for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Button`. It is highly recommended to provide this for button containing icon or image.

### setContentDescription

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
public @NonNull Button.Builder setContentDescription(
    @NonNull TypeBuilders.StringProp contentDescription
)
```

Sets the content description for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Button`. It is highly recommended to provide this for button containing icon or image.

While this field is statically accessible from 1.0, it's only bindable since version 1.2 and renderers supporting version 1.2 will use the dynamic value (if set).

### setCustomContent

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
public @NonNull Button.Builder setCustomContent(@NonNull LayoutElementBuilders.LayoutElement content)
```

Sets the custom content for this Button. Any previously added content will be overridden.

### setIconContent

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
public @NonNull Button.Builder setIconContent(@NonNull String imageResourceId)
```

Sets the content of this Button to be the given icon with the default size that is half of the set size of the button. Any previously added content will be overridden. Provided icon will be tinted to the given content color from `https://developer.android.com/reference/androidx/wear/protolayout/material/ButtonColors`. This icon should be image with chosen alpha channel and not an actual image.

### setIconContent

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
public @NonNull Button.Builder setIconContent(
    @NonNull String imageResourceId,
    @NonNull DimensionBuilders.DpProp size
)
```

Sets the content of this Button to be the given icon with the given size. Any previously added content will be overridden. Provided icon will be tinted to the given content color from `https://developer.android.com/reference/androidx/wear/protolayout/material/ButtonColors` and with the given size. This icon should be image with chosen alpha channel and not an actual image.

### setImageContent

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
public @NonNull Button.Builder setImageContent(@NonNull String imageResourceId)
```

Sets the content of this Button to be the given image, i.e. contacts photo. Any previously added content will be overridden.

### setSize

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
public @NonNull Button.Builder setSize(@NonNull DimensionBuilders.DpProp size)
```

Sets the size for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Button`. Strongly recommended values are `https://developer.android.com/reference/androidx/wear/protolayout/material/ButtonDefaults#DEFAULT_SIZE()`, `https://developer.android.com/reference/androidx/wear/protolayout/material/ButtonDefaults#LARGE_SIZE()` and `https://developer.android.com/reference/androidx/wear/protolayout/material/ButtonDefaults#EXTRA_LARGE_SIZE()`. If not set, `https://developer.android.com/reference/androidx/wear/protolayout/material/ButtonDefaults#DEFAULT_SIZE()` will be used.

### setSize

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
public @NonNull Button.Builder setSize(@Dimension(unit = 0) float size)
```

Sets the size for the `https://developer.android.com/reference/androidx/wear/protolayout/material/Button`. Strongly recommended values are `https://developer.android.com/reference/androidx/wear/protolayout/material/ButtonDefaults#DEFAULT_SIZE()`, `https://developer.android.com/reference/androidx/wear/protolayout/material/ButtonDefaults#LARGE_SIZE()` and `https://developer.android.com/reference/androidx/wear/protolayout/material/ButtonDefaults#EXTRA_LARGE_SIZE()`. If not set, `https://developer.android.com/reference/androidx/wear/protolayout/material/ButtonDefaults#DEFAULT_SIZE()` will be used.

### setTextContent

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
public @NonNull Button.Builder setTextContent(@NonNull String text)
```

Sets the content of this Button to be the given text with the default font for the set size (for the `https://developer.android.com/reference/androidx/wear/protolayout/material/ButtonDefaults#DEFAULT_SIZE()`, `https://developer.android.com/reference/androidx/wear/protolayout/material/ButtonDefaults#LARGE_SIZE()` and `https://developer.android.com/reference/androidx/wear/protolayout/material/ButtonDefaults#EXTRA_LARGE_SIZE()` is `https://developer.android.com/reference/androidx/wear/protolayout/material/Typography#TYPOGRAPHY_TITLE2()`, `https://developer.android.com/reference/androidx/wear/protolayout/material/Typography#TYPOGRAPHY_TITLE1()` and `https://developer.android.com/reference/androidx/wear/protolayout/material/Typography#TYPOGRAPHY_DISPLAY3()` respectively). Any previously added content will be overridden. Text should contain no more than 3 characters, otherwise it will overflow from the edges.

### setTextContent

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.0.0)

```
public @NonNull Button.Builder setTextContent(@NonNull String text, int typographyName)
```

Sets the content of this Button to be the given text with the given font. If you need more font related customization, consider using `https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder#setCustomContent(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement)` with `https://developer.android.com/reference/androidx/wear/protolayout/material/Text` component. Any previously added content will be overridden. Text should contain no more than 3 characters, otherwise it will overflow from the edges.