# Button

# Button

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)  
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 "View this page in Java")

<br />

```
class Button : LayoutElementBuilders.LayoutElement
```

<br />

*** ** * ** ***

ProtoLayout component[Button](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button)that represents clickable button with the given content.

The Button is circular in shape. The recommended sizes are defined in[ButtonDefaults](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/ButtonDefaults).

The recommended set of[ButtonColors](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/ButtonColors)styles can be obtained from[ButtonDefaults](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/ButtonDefaults)., e.g.[PRIMARY_COLORS](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/ButtonDefaults#PRIMARY_COLORS())to get a color scheme for a primary[Button](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button).

When accessing the contents of a container for testing, note that this element can't be simply casted back to the original type, i.e.:  

```kotlin
Button button = new Button...
Box box = new Box.Builder().addContent(button).build();

Button myButton = (Button) box.getContents().get(0);
```
will fail.

To be able to get[Button](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button)object from any layout element,[fromLayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button#fromLayoutElement(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement))method should be used, i.e.:  

```kotlin
Button myButton = Button.fromLayoutElement(box.getContents().get(0));
```

## Summary

|                                                                                                                ### Nested types                                                                                                                 |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `class `[Button.Builder](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button.Builder) Builder class for[Button](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button). |

|                                                                  ### Public functions                                                                  |
|--------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[Button](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button)`?`                                    | [fromLayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button#fromLayoutElement(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement))`(element: `[LayoutElementBuilders.LayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement)`)` Returns Button object from the given LayoutElement (e.g. one retrieved from a container's content with`container.getContents().get(index)`) if that element can be converted to Button. |
| [ButtonColors](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/ButtonColors)                                         | [getButtonColors](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button#getButtonColors())`()` Returns button color of this Button.                                                                                                                                                                                                                                                                                                                                                                                   |
| [ModifiersBuilders.Clickable](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/ModifiersBuilders.Clickable)                    | [getClickable](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button#getClickable())`()` Returns click event action associated with this Button.                                                                                                                                                                                                                                                                                                                                                                      |
| [TypeBuilders.StringProp](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/TypeBuilders.StringProp)`?`                         | [getContentDescription](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button#getContentDescription())`()` Returns content description for this Button.                                                                                                                                                                                                                                                                                                                                                               |
| [LayoutElementBuilders.LayoutElement](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement)`?` | [getCustomContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button#getCustomContent())`()` Returns the custom content of this Button if it has been added.                                                                                                                                                                                                                                                                                                                                                      |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?`                                                                   | [getIconContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button#getIconContent())`()` Returns the icon content of this Button if it has been added.                                                                                                                                                                                                                                                                                                                                                            |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?`                                                                   | [getImageContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button#getImageContent())`()` Returns the image content of this Button if it has been added.                                                                                                                                                                                                                                                                                                                                                         |
| [DimensionBuilders.ContainerDimension](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/DimensionBuilders.ContainerDimension)  | [getSize](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button#getSize())`()` Returns size for this Button.                                                                                                                                                                                                                                                                                                                                                                                                          |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`?`                                                                   | [getTextContent](https://developer.android.com/reference/kotlin/androidx/wear/protolayout/material/Button#getTextContent())`()` Returns the text content of this Button if it has been added.                                                                                                                                                                                                                                                                                                                                                            |

## Public functions

### fromLayoutElement

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

```
java-static fun fromLayoutElement(element: LayoutElementBuilders.LayoutElement): Button?
```

Returns Button object from the given LayoutElement (e.g. one retrieved from a container's content with`container.getContents().get(index)`) if that element can be converted to Button. Otherwise, it will return null.  

### getButtonColors

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

```
fun getButtonColors(): ButtonColors
```

Returns button color of this Button.

Note that the content color will be unset if the content of this Button is an image.  

### getClickable

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

```
fun getClickable(): ModifiersBuilders.Clickable
```

Returns click event action associated with this Button.  

### getContentDescription

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

```
fun getContentDescription(): TypeBuilders.StringProp?
```

Returns content description for this Button.  

### getCustomContent

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

```
fun getCustomContent(): LayoutElementBuilders.LayoutElement?
```

Returns the custom content of this Button if it has been added. Otherwise, it returns null.  

### getIconContent

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

```
fun getIconContent(): String?
```

Returns the icon content of this Button if it has been added. Otherwise, it returns null.  

### getImageContent

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

```
fun getImageContent(): String?
```

Returns the image content of this Button if it has been added. Otherwise, it returns null.  

### getSize

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

```
fun getSize(): DimensionBuilders.ContainerDimension
```

Returns size for this Button.  

### getTextContent

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

```
fun getTextContent(): String?
```

Returns the text content of this Button if it has been added. Otherwise, it returns null.