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

*** ** * ** ***


```
public class Button implements LayoutElementBuilders.LayoutElement
```

<br />

*** ** * ** ***

ProtoLayout component `https://developer.android.com/reference/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 `https://developer.android.com/reference/androidx/wear/protolayout/material/ButtonDefaults`.

The recommended set of `https://developer.android.com/reference/androidx/wear/protolayout/material/ButtonColors` styles can be obtained from `https://developer.android.com/reference/androidx/wear/protolayout/material/ButtonDefaults`., e.g. `https://developer.android.com/reference/androidx/wear/protolayout/material/ButtonDefaults#PRIMARY_COLORS()` to get a color scheme for a primary `https://developer.android.com/reference/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.:

```
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 `https://developer.android.com/reference/androidx/wear/protolayout/material/Button` object from any layout element, `https://developer.android.com/reference/androidx/wear/protolayout/material/Button#fromLayoutElement(androidx.wear.protolayout.LayoutElementBuilders.LayoutElement)` method should be used, i.e.:

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

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/wear/protolayout/material/Button.Builder` Builder class for `https://developer.android.com/reference/androidx/wear/protolayout/material/Button`. |

| ### Public methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/wear/protolayout/material/Button` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Button#fromLayoutElement(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 element)` 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. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/material/ButtonColors` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Button#getButtonColors()()` Returns button color of this Button. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/ModifiersBuilders.Clickable` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Button#getClickable()()` Returns click event action associated with this Button. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/wear/protolayout/TypeBuilders.StringProp` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Button#getContentDescription()()` Returns content description for this Button. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.LayoutElement` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Button#getCustomContent()()` Returns the custom content of this Button if it has been added. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Button#getIconContent()()` Returns the icon content of this Button if it has been added. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Button#getImageContent()()` Returns the image content of this Button if it has been added. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/wear/protolayout/DimensionBuilders.ContainerDimension` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Button#getSize()()` Returns size for this Button. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/wear/protolayout/material/Button#getTextContent()()` Returns the text content of this Button if it has been added. |

## Public methods

### fromLayoutElement

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

```
public static @Nullable Button fromLayoutElement(@NonNull LayoutElementBuilders.LayoutElement element)
```

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)

```
public @NonNull ButtonColors getButtonColors()
```

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)

```
public @NonNull ModifiersBuilders.Clickable getClickable()
```

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)

```
public @Nullable TypeBuilders.StringProp getContentDescription()
```

Returns content description for this Button.

### getCustomContent

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

```
public @Nullable LayoutElementBuilders.LayoutElement getCustomContent()
```

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)

```
public @Nullable String getIconContent()
```

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)

```
public @Nullable String getImageContent()
```

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)

```
public @NonNull DimensionBuilders.ContainerDimension getSize()
```

Returns size for this Button.

### getTextContent

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

```
public @Nullable String getTextContent()
```

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