Chip Drawable
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:
- setBounds, taking into account getIntrinsicHeight and getIntrinsicWidth.
- draw
- setCallback, to support invalidations on the chip drawable or any of its child drawables. This includes animations.
- setState, to support checking the chip, and touch/mouse/keyboard interactions on the chip.
- setCloseIconState, to support touch, mouse, or keyboard interactions on the close icon.
- setHotspot
- setLayoutDirection, to support RTL mode.
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
Properties
Functions
[ChipDrawable.getBounds().left, ChipDrawable.getBounds().top]
).
[ChipDrawable.getBounds().left, ChipDrawable.getBounds().top]
).