Chip.Builder


class Chip.Builder


A builder of Chip.

Summary

Public constructors

Public functions

Chip

Constructs the Chip defined by this builder.

Chip.Builder
setEndIcon(endIcon: CarIcon)

Sets the icon to display at the end of the chip.

Chip.Builder

Sets the OnClickListener to be called when the chip is clicked.

Chip.Builder
setSelected(isSelected: Boolean)

Sets the selected state of the chip, similar to how toggle has a selected state.

Chip.Builder
setStartIcon(startIcon: CarIcon)

Sets the icon to display at the start of the chip.

Chip.Builder

Sets the style of the chip.

Chip.Builder
setTitle(title: CarText)

Sets the title of the chip, with support for multiple length variants.

Chip.Builder

Sets the title of the chip.

Public constructors

Builder

Added in 1.8.0-beta01
Builder()

Public functions

build

Added in 1.8.0-beta01
fun build(): Chip

Constructs the Chip defined by this builder.

Throws
java.lang.IllegalStateException

if the chip does not have a title, start icon, or end icon.

java.lang.IllegalStateException

if the chip does not have an OnClickListener.

setEndIcon

Added in 1.8.0-beta01
fun setEndIcon(endIcon: CarIcon): Chip.Builder

Sets the icon to display at the end of the chip.

The icon must conform to DEFAULT.

A chip without an endIcon must set setTitle OR setStartIcon or the build will throw an exception. Without an endIcon, the host will render the chip with the passed in title and/or startIcon (depending on which has been set).

The icon will attempt to use the most specific tint supplied; this is, it will try to use the first tint found in the following priority: 1. setTint 2. setStylesetContentColor 3. setStyle content color 4. A host supplied color that matches the setSelected state Note that if the supplied color fails to meet contrast requirements, a host-supplied fallback that matches the selected state will be used.

Rasterized images such as (TYPE_BITMAP) images will not have any tints unless explicitly supplied through setTint..

Throws
java.lang.NullPointerException

if endIcon is null

setOnClickListener

Added in 1.8.0-beta01
fun setOnClickListener(onClickListener: OnClickListener): Chip.Builder

Sets the OnClickListener to be called when the chip is clicked.

Note that the listener relates to the UI events and will be executed on the main thread using getMainLooper.

Throws
java.lang.NullPointerException

if onClickListener is null

setSelected

Added in 1.8.0-beta01
fun setSelected(isSelected: Boolean): Chip.Builder

Sets the selected state of the chip, similar to how toggle has a selected state.

If the selected state is not set, the default will be false

If a custom style is provided through setStyle, changing this selected boolean value will not automatically change the color of this chip. The custom style must also be updated to reflect the selected state. See setStyle or setStyle for more details.

setStartIcon

Added in 1.8.0-beta01
fun setStartIcon(startIcon: CarIcon): Chip.Builder

Sets the icon to display at the start of the chip.

The icon must conform to DEFAULT.

A chip without a startIcon must set setTitle OR setEndIcon or the build will throw an exception. Without a startIcon, the host will render the chip with the passed in title and/or endIcon (depending on which has been set).

The icon will attempt to use the most specific tint supplied; this is, it will try to use the first tint found in the following priority: 1. setTint 2. setStylesetContentColor 3. setStyle content color 4. A host supplied color that matches the setSelected state Note that if the supplied color fails to meet contrast requirements, a host-supplied fallback that matches the selected state will be used.

Rasterized images such as (TYPE_BITMAP) images will not have any tints unless explicitly supplied through setTint..

Throws
java.lang.NullPointerException

if startIcon is null

setStyle

Added in 1.8.0-beta01
fun setStyle(style: ChipStyle): Chip.Builder

Sets the style of the chip.

This style overrides the style set in the ChipSection if one is provided. Any fields not explicitly set here or in the ChipSection will fall back to the host's default colors. If the style is not set or if the colors do not meet the contrast requirements, the host will set the chip styling to defaults based on the setSelected state.

Throws
java.lang.NullPointerException

if style is null

setTitle

Added in 1.8.0-beta01
fun setTitle(title: CarText): Chip.Builder

Sets the title of the chip, with support for multiple length variants.

A chip without a title must set setStartIcon OR setEndIcon or the build will throw an exception. Without a title, the host will render the chip with the passed in startIcon and/or endIcon (depending on which has been set).

The text must conform to TEXT_WITH_COLORS.

Developers can provide a shorter addVariant variant in case their title length exceeds the chip width limit enforced by the host.

Throws
java.lang.NullPointerException

if title is null

java.lang.IllegalArgumentException

if title is empty, or if it contains unsupported spans

setTitle

Added in 1.8.0-beta01
fun setTitle(title: CharSequence): Chip.Builder

Sets the title of the chip.

A chip without a title must set setStartIcon OR setEndIcon or the build will throw an exception. Without a title, the host will render the chip with the passed in startIcon and/or endIcon (depending on which has been set).

The text must conform to TEXT_WITH_COLORS.

Throws
java.lang.NullPointerException

if title is null

java.lang.IllegalArgumentException

if title is empty, or if it contains unsupported spans