class Chip.Builder


Builder class for androidx.wear.protolayout.material.Chip.

Summary

Public constructors

Builder(
    context: Context,
    clickable: ModifiersBuilders.Clickable,
    deviceParameters: DeviceParametersBuilders.DeviceParameters
)

Creates a builder for the Chip with associated action.

Public functions

Chip

Constructs and returns Chip with the provided content and look.

Chip.Builder

Sets the colors for the Chip.

Chip.Builder
setContentDescription(contentDescription: CharSequence)

Sets the static content description for the Chip.

Chip.Builder

Sets the content description for the Chip.

Chip.Builder

Sets the custom content for the Chip.

Chip.Builder
setHorizontalAlignment(horizontalAlignment: Int)

Sets the horizontal alignment in the chip.

Chip.Builder
setIconContent(imageResourceId: String)

Sets the icon for the Chip.

Chip.Builder

Sets the primary label for the Chip.

Chip.Builder

Sets the secondary label for the Chip.

Chip.Builder

Sets the width of Chip.

Chip.Builder
setWidth(width: @Dimension(unit = 0) Float)

Sets the width of TitleChip.

Public constructors

Builder

Added in 1.0.0
Builder(
    context: Context,
    clickable: ModifiersBuilders.Clickable,
    deviceParameters: DeviceParametersBuilders.DeviceParameters
)

Creates a builder for the Chip with associated action. It is required to add content later with setters.

Parameters
context: Context

The application's context.

clickable: ModifiersBuilders.Clickable

Associated Clickable for click events. When the Chip is clicked it will fire the associated action.

deviceParameters: DeviceParametersBuilders.DeviceParameters

The device parameters used to derive defaults for this Chip.

Public functions

build

Added in 1.0.0
fun build(): Chip

Constructs and returns Chip with the provided content and look.

setChipColors

Added in 1.0.0
fun setChipColors(chipColors: ChipColors): Chip.Builder

Sets the colors for the Chip. If set, getBackgroundColor will be used for the background of the button, getContentColor for main text, getSecondaryContentColor for label text and getIconColor will be used as color for the icon itself. If not set, PRIMARY_COLORS will be used.

setContentDescription

Added in 1.0.0
fun setContentDescription(contentDescription: CharSequence): Chip.Builder

Sets the static content description for the Chip. It is highly recommended to provide this for chip containing icon.

setContentDescription

Added in 1.0.0
fun setContentDescription(contentDescription: TypeBuilders.StringProp): Chip.Builder

Sets the content description for the Chip. It is highly recommended to provide this for chip containing icon.

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
fun setCustomContent(content: LayoutElementBuilders.LayoutElement): Chip.Builder

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

setHorizontalAlignment

Added in 1.0.0
fun setHorizontalAlignment(horizontalAlignment: Int): Chip.Builder

Sets the horizontal alignment in the chip. It is strongly recommended that the content of the chip is start-aligned if there is more than primary text in it. By default, HORIZONTAL_ALIGN_CENTER will be used when only a primary label is present. Otherwise HORIZONTAL_ALIGN_START will be used.

setIconContent

Added in 1.0.0
fun setIconContent(imageResourceId: String): Chip.Builder

Sets the icon for the Chip. Any previously added custom content will be overridden. Provided icon will be tinted to the given content color from . This icon should be image with chosen alpha channel and not an actual image. If icon is set, primary label must be set too with setPrimaryLabelContent.

setPrimaryLabelContent

Added in 1.0.0
fun setPrimaryLabelContent(primaryLabel: String): Chip.Builder

Sets the primary label for the Chip. Any previously added custom content will be overridden. Primary label can be on 1 or 2 lines, depending on the length and existence of secondary label.

setSecondaryLabelContent

Added in 1.0.0
fun setSecondaryLabelContent(secondaryLabel: String): Chip.Builder

Sets the secondary label for the Chip. Any previously added custom content will be overridden. If secondary label is set, primary label must be set too with setPrimaryLabelContent.

setWidth

Added in 1.0.0
fun setWidth(width: DimensionBuilders.ContainerDimension): Chip.Builder

Sets the width of Chip. If not set, default value will be set to fill the screen.

setWidth

Added in 1.0.0
fun setWidth(width: @Dimension(unit = 0) Float): Chip.Builder

Sets the width of TitleChip. If not set, default value will be set to fill the screen.