ChipDrawable

SESL variant ChipDrawable contains all the layout and draw logic for Chip.

You can use ChipDrawable directly in contexts that require a Drawable. For example, an auto-complete enabled EditText can replace snippets of text with a ChipDrawable to represent it as a semantic entity. To create an instance of ChipDrawable, use createFromResource and pass in an XML resource in this form:


<chip xmlns:app="http://schemas.android.com/apk/res-auto"
    android:text="Hello, World!"/>

The basic attributes you can set are:

  • android:checkable - If true, the chip can be toggled. If false, the chip acts like a button.
  • android:text - Sets the text of the chip.
  • app:chipIcon - Sets the icon of the chip, or use @null to display no icon. Usually on the left.
  • app:checkedIcon - Sets a custom icon to use when checked, or use @null to display no icon. Usually on the left.
  • app:closeIcon - Sets a custom icon that the user can click to close, or use @null to display no icon. Usually on the right.
  • ellipsize - Does not support MARQUEE because chip text should not scroll.

When used in this stand-alone mode, the host view must explicitly manage the ChipDrawable's state:

ChipDrawable's horizontal layout is as follows:

  chipStartPadding     iconEndPadding     closeIconStartPadding         chipEndPadding
   +                    +                                    +                      +
   |                    |                                    |                      |
   |  iconStartPadding  |  textStartPadding   textEndPadding | closeIconEndPadding  |
   |   +                |    +                            +  |                  +   |
   |   |                |    |                            |  |                  |   |
   v   v                v    v                            v  v                  v   v
+-----+----+-----------+----+----+---------------------+----+----+----------+----+-----+
|     |    |       XX  |    |    |  XX   X  X  X  XXX  |    |    | X      X |    |     |
|     |    |      XX   |    |    | X  X  X  X  X  X  X |    |    |  XX  XX  |    |     |
|     |    |  XX XX    |    |    | X     XXXX  X  XXX  |    |    |    XX    |    |     |
|     |    |   XXX     |    |    | X  X  X  X  X  X    |    |    |  XX  XX  |    |     |
|     |    |    X      |    |    |  XX   X  X  X  X    |    |    | X      X |    |     |
+-----+----+-----------+----+----+---------------------+----+----+----------+----+-----+
                 ^                           ^                         ^
                 |                           |                         |
                 +                           +                         +
            chipIconSize                  *dynamic*              closeIconSize

ChipDrawable contains three child drawables: chipIcon, checkedIcon, and closeIcon. chipIcon and checkedIcon inherit the state of this drawable, but closeIcon contains its own state that you can set with setCloseIconState.

For more information, see the component developer guidance and design guidelines.

See also

Types

Link copied to clipboard
interface Delegate
Delegate interface to be implemented by Views that own a ChipDrawable.

Properties

Link copied to clipboard
open var alpha: Int
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Padding at the end of the chip, after the close icon.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Padding at the start of the chip, before the icon.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Padding at the end of the close icon, before the end of the chip.
Link copied to clipboard
Link copied to clipboard
Padding at the start of the close icon, after the text.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Padding at the end of the icon, before the text.
Link copied to clipboard
Padding at the start of the icon, after the start of the chip.
Link copied to clipboard
Link copied to clipboard
@get:Px
open var maxWidth: Int
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Padding at the end of the text, before the close icon.
Link copied to clipboard
Padding at the start of the text, after the icon.
Link copied to clipboard

Functions

Link copied to clipboard
open fun createFromAttributes(@NonNull context: Context, @Nullable attrs: AttributeSet, @AttrRes defStyleAttr: Int, @StyleRes defStyleRes: Int): ChipDrawable
Returns a ChipDrawable from the given attributes.
Link copied to clipboard
Returns a ChipDrawable from the given XML resource.
Link copied to clipboard
open fun draw(@NonNull canvas: Canvas)
Link copied to clipboard
open fun getChipTouchBounds(@NonNull bounds: RectF)
Returns the chip's ChipDrawable-absolute bounds (top-left is [ChipDrawable.getBounds().left, ChipDrawable.getBounds().top]).
Link copied to clipboard
Describes the current state of the close icon.
Link copied to clipboard
Returns the close icon's ChipDrawable-absolute bounds (top-left is [ChipDrawable.getBounds().left, ChipDrawable.getBounds().top]).
Link copied to clipboard
Link copied to clipboard
Returns the height at which the chip would like to be laid out.
Link copied to clipboard
Returns the width at which the chip would like to be laid out.
Link copied to clipboard
open fun getOpacity(): Int
Link copied to clipboard
open fun getOutline(@NonNull outline: Outline)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun isCheckable(): Boolean
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Indicates whether the close icon drawable will change its appearance based on state.
Link copied to clipboard
Link copied to clipboard
open fun isStateful(): Boolean
Indicates whether this chip drawable will change its appearance based on state.
Link copied to clipboard
open fun onLayoutDirectionChanged(layoutDirection: Int): Boolean
Link copied to clipboard
open fun onStateChange(@NonNull state: Array<Int>): Boolean
Link copied to clipboard
open fun onTextSizeChange()
Handles a change in the text's size.
Link copied to clipboard
open fun scheduleDrawable(@NonNull who: Drawable, @NonNull what: Runnable, when: Long)
Link copied to clipboard
open fun setCheckable(checkable: Boolean)
Link copied to clipboard
Link copied to clipboard
open fun setCheckedIconEnabled(checkedIconEnabled: Boolean)
Link copied to clipboard
Link copied to clipboard
Sets this chip's checked icon using a resource id.
Link copied to clipboard
Sets the checked icon's color tint using a resource ID.
Link copied to clipboard
open fun setCheckedIconVisible(checkedIconVisible: Boolean)
Link copied to clipboard
Sets this chip's background color using a resource id.
Link copied to clipboard
Link copied to clipboard
Sets this chip's end padding using a resource id.
Link copied to clipboard
open fun setChipIconEnabled(chipIconEnabled: Boolean)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Sets this chip icon's size using a resource id.
Link copied to clipboard
Sets the chip icon's color tint using a resource ID.
Link copied to clipboard
open fun setChipIconVisible(chipIconVisible: Boolean)
Link copied to clipboard
Sets this chip's minimum height using a resource id.
Link copied to clipboard
Sets this chip's start padding using a resource id.
Link copied to clipboard
Sets this chip's stroke color using a resource id.
Link copied to clipboard
Sets this chip's stroke width using a resource id.
Link copied to clipboard
open fun setCloseIconEnabled(closeIconEnabled: Boolean)
Link copied to clipboard
Link copied to clipboard
Sets the end padding for this chip's close icon using a resource id.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Sets the start padding for this chip's close icon using a resource id.
Link copied to clipboard
open fun setCloseIconState(@NonNull stateSet: Array<Int>): Boolean
Specify a set of states for the close icon.
Link copied to clipboard
Link copied to clipboard
open fun setCloseIconVisible(closeIconVisible: Boolean)
Link copied to clipboard
Sets the View delegate that owns this ChipDrawable.
Link copied to clipboard
Link copied to clipboard
Sets this chip's hide motion spec using a resource id.
Link copied to clipboard
Sets the end padding for this chip's icon using a resource id.
Link copied to clipboard
Sets the start padding for this chip's icon using a resource id.
Link copied to clipboard
Sets this chip's ripple color using a resource id.
Link copied to clipboard
Sets this chip's show motion spec using a resource id.
Link copied to clipboard
open fun setTextAppearance(@Nullable textAppearance: TextAppearance)
Link copied to clipboard
Link copied to clipboard
open fun setTextColor(@ColorInt color: Int)
Link copied to clipboard
Sets the end padding for this chip's text using a resource id.
Link copied to clipboard
open fun setTextResource(@StringRes id: Int)
Link copied to clipboard
open fun setTextSize(@Dimension size: Float)
Link copied to clipboard
Sets the start padding for this chip's text using a resource id.
Link copied to clipboard
Link copied to clipboard
open fun setTintMode(@NonNull tintMode: PorterDuff.Mode)
Link copied to clipboard
open fun setVisible(visible: Boolean, restart: Boolean): Boolean
Link copied to clipboard