# Button.Builder

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder "View this page in Java")

<br />

```
class Button.Builder
```

<br />

*** ** * ** ***

Builder class for[Button](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button).

## Summary

|                                                                                                                                                                                                                                                                                        ### Public constructors                                                                                                                                                                                                                                                                                        |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder#Builder(android.content.Context,androidx.wear.protolayout.ModifiersBuilders.Clickable))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`, clickable: `[ModifiersBuilders.Clickable](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ModifiersBuilders.Clickable)`)` Creates a builder for the[Button](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button)from the given content. |

|                                                ### Public functions                                                |
|--------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Button](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button)                 | [build](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder#build())`()` Constructs and returns[Button](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button)with the provided field and look.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| [Button.Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder) | [setButtonColors](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder#setButtonColors(androidx.wear.protolayout.material.ButtonColors))`(buttonColors: `[ButtonColors](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/ButtonColors)`)` Sets the colors for the[Button](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| [Button.Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder) | [setContentDescription](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder#setContentDescription(java.lang.CharSequence))`(contentDescription: `[CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`)` Sets the static content description for the[Button](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| [Button.Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder) | [setContentDescription](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder#setContentDescription(androidx.wear.protolayout.TypeBuilders.StringProp))`(contentDescription: `[TypeBuilders.StringProp](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/TypeBuilders.StringProp)`)` Sets the content description for the[Button](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| [Button.Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder) | [setCustomContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder#setCustomContent(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement))`(content: `[LayoutElementBuilders.LayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement)`)` Sets the custom content for this Button.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| [Button.Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder) | [setIconContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder#setIconContent(java.lang.String))`(imageResourceId: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` 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.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| [Button.Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder) | [setIconContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder#setIconContent(java.lang.String,androidx.wear.protolayout.DimensionBuilders.DpProp))`(imageResourceId: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`, size: `[DimensionBuilders.DpProp](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/DimensionBuilders.DpProp)`)` Sets the content of this Button to be the given icon with the given size.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| [Button.Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder) | [setImageContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder#setImageContent(java.lang.String))`(imageResourceId: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Sets the content of this Button to be the given image, i.e. contacts photo.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| [Button.Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder) | [setSize](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder#setSize(androidx.wear.protolayout.DimensionBuilders.DpProp))`(size: `[DimensionBuilders.DpProp](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/DimensionBuilders.DpProp)`)` Sets the size for the[Button](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| [Button.Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder) | [setSize](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder#setSize(float))`(size: @`[Dimension](https://developer.android.com/reference/kotlin/androidx/annotation/Dimension)`(unit = 0) `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`)` Sets the size for the[Button](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| [Button.Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder) | [setTextContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder#setTextContent(java.lang.String))`(text: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Sets the content of this Button to be the given text with the default font for the set size (for the[DEFAULT_SIZE](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/ButtonDefaults#DEFAULT_SIZE()),[LARGE_SIZE](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/ButtonDefaults#LARGE_SIZE())and[EXTRA_LARGE_SIZE](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/ButtonDefaults#EXTRA_LARGE_SIZE())is[TYPOGRAPHY_TITLE2](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Typography#TYPOGRAPHY_TITLE2()),[TYPOGRAPHY_TITLE1](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Typography#TYPOGRAPHY_TITLE1())and[TYPOGRAPHY_DISPLAY3](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Typography#TYPOGRAPHY_DISPLAY3())respectively). |
| [Button.Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder) | [setTextContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder#setTextContent(java.lang.String,int))`(text: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`, typographyName: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` 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)  

```
Builder(context: Context, clickable: ModifiersBuilders.Clickable)
```

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

|                                                                    Parameters                                                                    |
|--------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)                                                       | The application's context.                                                                                                                                                                                  |
| `clickable: `[ModifiersBuilders.Clickable](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ModifiersBuilders.Clickable) | Associated[Clickable](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ModifiersBuilders.Clickable)for click events. When the Button is clicked it will fire the associated action. |

## Public functions

### build

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

```
fun build(): Button
```

Constructs and returns[Button](https://developer.android.com/reference/kotlin/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)  

```
fun setButtonColors(buttonColors: ButtonColors): Button.Builder
```

Sets the colors for the[Button](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button). If not set,[PRIMARY_COLORS](https://developer.android.com/reference/kotlin/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)  

```
fun setContentDescription(contentDescription: CharSequence): Button.Builder
```

Sets the static content description for the[Button](https://developer.android.com/reference/kotlin/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)  

```
fun setContentDescription(contentDescription: TypeBuilders.StringProp): Button.Builder
```

Sets the content description for the[Button](https://developer.android.com/reference/kotlin/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)  

```
fun setCustomContent(content: LayoutElementBuilders.LayoutElement): Button.Builder
```

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)  

```
fun setIconContent(imageResourceId: String): Button.Builder
```

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[ButtonColors](https://developer.android.com/reference/kotlin/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)  

```
fun setIconContent(imageResourceId: String, size: DimensionBuilders.DpProp): Button.Builder
```

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[ButtonColors](https://developer.android.com/reference/kotlin/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)  

```
fun setImageContent(imageResourceId: String): Button.Builder
```

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)  

```
fun setSize(size: DimensionBuilders.DpProp): Button.Builder
```

Sets the size for the[Button](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button). Strongly recommended values are[DEFAULT_SIZE](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/ButtonDefaults#DEFAULT_SIZE()),[LARGE_SIZE](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/ButtonDefaults#LARGE_SIZE())and[EXTRA_LARGE_SIZE](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/ButtonDefaults#EXTRA_LARGE_SIZE()). If not set,[DEFAULT_SIZE](https://developer.android.com/reference/kotlin/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)  

```
fun setSize(size: @Dimension(unit = 0) Float): Button.Builder
```

Sets the size for the[Button](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button). Strongly recommended values are[DEFAULT_SIZE](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/ButtonDefaults#DEFAULT_SIZE()),[LARGE_SIZE](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/ButtonDefaults#LARGE_SIZE())and[EXTRA_LARGE_SIZE](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/ButtonDefaults#EXTRA_LARGE_SIZE()). If not set,[DEFAULT_SIZE](https://developer.android.com/reference/kotlin/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)  

```
fun setTextContent(text: String): Button.Builder
```

Sets the content of this Button to be the given text with the default font for the set size (for the[DEFAULT_SIZE](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/ButtonDefaults#DEFAULT_SIZE()),[LARGE_SIZE](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/ButtonDefaults#LARGE_SIZE())and[EXTRA_LARGE_SIZE](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/ButtonDefaults#EXTRA_LARGE_SIZE())is[TYPOGRAPHY_TITLE2](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Typography#TYPOGRAPHY_TITLE2()),[TYPOGRAPHY_TITLE1](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Typography#TYPOGRAPHY_TITLE1())and[TYPOGRAPHY_DISPLAY3](https://developer.android.com/reference/kotlin/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)  

```
fun setTextContent(text: String, typographyName: Int): Button.Builder
```

Sets the content of this Button to be the given text with the given font. If you need more font related customization, consider using[setCustomContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder#setCustomContent(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement))with[Text](https://developer.android.com/reference/kotlin/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.