Chip
Chips are compact elements that represent an attribute, text, entity, or action. They allow users to enter information, select a choice, filter content, or trigger an action.
The Chip widget is a thin view wrapper around the ChipDrawable, which contains all of the layout and draw logic. The extra logic exists to support touch, mouse, keyboard, and accessibility navigation. The main chip and close icon are considered to be separate logical sub-views, and contain their own navigation behavior and state.
All attributes from R.styleable.Chip
are supported. Do not use the
android:background
attribute. It will be ignored because Chip manages its own background Drawable. Also do not use the android:drawableStart
and android:drawableEnd
attributes. They will be ignored because Chip manages its own start (app:chipIcon
) and end (app:closeIcon
) drawables. 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
andapp:chipIconEnabled
- Sets the icon of the chip. Usually on the left.app:checkedIcon
andapp:checkedIconEnabled
- Sets a custom icon to use when checked. Usually on the left.app:closeIcon
andapp:closeIconEnabled
- Sets a custom icon that the user can click to close. Usually on the right.
You can register a listener on the main chip with setOnClickListener or setOnCheckedChangeListener. You can register a listener on the close icon with setOnCloseIconClickListener.
For proper rendering of the ancestor TextView in RTL mode, call setLayoutDirection with View.LAYOUT_DIRECTION_LOCALE
. By default, TextView's layout rendering sets the text padding in LTR on initial rendering and it only renders correctly after the layout has been invalidated so you need to ensure that initial rendering has the correct layout.
For more information, see the component developer guidance and design guidelines.
See also
Functions
minTargetPx
.