public class Chip implements ChipDrawable.Delegate, Shapeable


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 and app:chipIconEnabled - Sets the icon of the chip. Usually on the left.
  • app:checkedIcon and app:checkedIconEnabled - Sets a custom icon to use when checked. Usually on the left.
  • app:closeIcon and app: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
ChipDrawable

Summary

Public constructors

Chip(Context context)
Chip(Context context, AttributeSet attrs)
Chip(Context context, AttributeSet attrs, int defStyleAttr)

Public methods

boolean
dispatchKeyEvent(KeyEvent event)
boolean
ensureAccessibleTouchTarget(int minTargetPx)

Extends the touch target of this chip using a InsetDrawable if chip's intrinsic width / height is smaller than the minTargetPx.

CharSequence
Drawable
Drawable

Returns this chip's checked icon.

ColorStateList

Returns the android.content.res.ColorStateList used to tint the checked icon.

ColorStateList

Returns this chip's background color.

float

Returns this chip's corner radius.

Drawable

Returns the ChipDrawable backing this chip.

float

Returns this chip's end padding.

Drawable

Returns this chip's icon.

float

Returns this chip's icon size.

ColorStateList

Returns the android.content.res.ColorStateList used to tint the chip icon.

float

Returns this chip's minimum height.

float

Returns this chip's start padding.

ColorStateList

Returns this chip's stroke color.

float

Returns this chip's stroke width.

CharSequence

This method is deprecated.

Use getText instead.

Drawable

Returns this chip's close icon.

CharSequence

Returns this chip's close icon content description.

float

Returns the end padding for this chip's close icon.

float

Returns this chip's close icon size.

float

Returns the start padding for this chip's close icon.

ColorStateList

Returns the tint color for this chip's close icon.

TruncateAt
void
MotionSpec

Returns this chip's hide motion spec.

float

Returns the end padding for this chip's icon.

float

Returns the start padding for this chip's icon.

abstract int
ColorStateList

Returns this chip's ripple color.

ShapeAppearanceModel

Returns the ShapeAppearanceModel used for the shape definition.

MotionSpec

Returns this chip's show motion spec.

float

Returns the end padding for this chip's text.

float

Returns the start padding for this chip's text.

boolean

Returns whether this chip is checkable.

boolean

This method is deprecated.

Use isCheckedIconVisible instead.

boolean

Returns whether this chip's checked icon is visible.

boolean

This method is deprecated.

Use isChipIconVisible instead.

boolean

Returns whether this chip's icon is visible.

boolean

This method is deprecated.

Use isCloseIconVisible instead.

boolean

Returns whether this chip's close icon is visible.

void

Handles a change in the ChipDrawable's size.

boolean
onHoverEvent(MotionEvent event)
void
onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
PointerIcon
onResolvePointerIcon(MotionEvent event, int pointerIndex)
void
onRtlPropertiesChanged(int layoutDirection)
boolean
onTouchEvent(MotionEvent event)
boolean

Call this chip's close icon click listener, if it is defined.

void

Sets this chip's accessibility class name.

void
setBackground(Drawable background)
void
setBackgroundColor(int color)
void
setBackgroundDrawable(Drawable background)
void
void
setBackgroundTintList(ColorStateList tint)
void
setBackgroundTintMode(Mode tintMode)
void
setCheckable(boolean checkable)

Sets whether this chip is checkable.

void

Sets whether this chip is checkable using a resource id.

void
setChecked(boolean checked)
void
setCheckedIcon(Drawable checkedIcon)

Sets this chip's checked icon.

void
setCheckedIconEnabled(boolean checkedIconEnabled)

This method is deprecated.

Use setCheckedIconVisible instead.

void

This method is deprecated.

Use setCheckedIconVisible instead.

void

Sets this chip's checked icon using a resource id.

void
setCheckedIconTint(ColorStateList checkedIconTint)

Sets this chip's checked icon's color tint using the specified .

void

Sets this chip's checked icon's color tint using a resource id.

void
setCheckedIconVisible(boolean checkedIconVisible)

Sets whether this chip's checked icon is visible.

void

Sets whether this chip's checked icon is visible using a resource id.

void
setChipBackgroundColor(ColorStateList chipBackgroundColor)

Sets this chip's background color.

void

Sets this chip's background color using a resource id.

void
setChipCornerRadius(float chipCornerRadius)

This method is deprecated.

call withCornerSize or call toBuilder on the getShapeAppearanceModel, modify the shape using the builder and then call setShapeAppearanceModel.

void

This method is deprecated.

call withCornerSize or call toBuilder on the getShapeAppearanceModel, modify the shape using the builder and then call setShapeAppearanceModel.

void

Sets the ChipDrawable backing this chip.

void
setChipEndPadding(float chipEndPadding)

Sets this chip's end padding.

void

Sets this chip's end padding using a resource id.

void
setChipIcon(Drawable chipIcon)

Sets this chip's icon.

void
setChipIconEnabled(boolean chipIconEnabled)

This method is deprecated.

Use setChipIconVisible instead.

void

This method is deprecated.

Use setChipIconVisible instead.

void

Sets this chip's icon using a resource id.

void
setChipIconSize(float chipIconSize)

Sets this chip icon's size.

void

Sets this chip icon's size using a resource id.

void
setChipIconTint(ColorStateList chipIconTint)

Sets this chip icon's color tint using the specified .

void

Sets this chip icon's color tint using a resource id.

void
setChipIconVisible(boolean chipIconVisible)

Sets whether this chip's icon is visible.

void

Sets the visibility of this chip's icon using a resource id.

void
setChipMinHeight(float minHeight)

Sets this chip's minimum height.

void

Sets this chip's minimum height using a resource id.

void
setChipStartPadding(float chipStartPadding)

Sets this chip's start padding.

void

Sets this chip's start padding using a resource id.

void
setChipStrokeColor(ColorStateList chipStrokeColor)

Sets this chip's stroke color.

void

Sets this chip's stroke color using a resource id.

void
setChipStrokeWidth(float chipStrokeWidth)

Sets this chip's stroke width.

void

Sets this chip's stroke width using a resource id.

void

This method is deprecated.

Use setText instead.

void

This method is deprecated.

Use setText instead.

void
setCloseIcon(Drawable closeIcon)

Sets this chip's close icon.

void
setCloseIconContentDescription(
    CharSequence closeIconContentDescription
)

Sets the content description for this chip's close icon.

void
setCloseIconEnabled(boolean closeIconEnabled)

This method is deprecated.

Use setCloseIconVisible instead.

void

This method is deprecated.

Use setCloseIconVisible instead.

void
setCloseIconEndPadding(float closeIconEndPadding)

Sets the end padding for this chip's close icon.

void

Sets the end padding for this chip's close icon using a resource id.

void

Sets this chip's close icon using a resource id.

void
setCloseIconSize(float closeIconSize)

Sets this chip's close icon size.

void

Sets this chip's close icon size using a resource id.

void
setCloseIconStartPadding(float closeIconStartPadding)

Sets the start padding for this chip's close icon.

void

Sets the start padding for this chip's close icon using a resource id.

void
setCloseIconTint(ColorStateList closeIconTint)

Sets the tint color for this chip's close icon.

void

Sets the tint color for this chip's close icon using a resource id.

void
setCloseIconVisible(boolean closeIconVisible)

Sets whether this chip close icon is visible.

void

Sets whether this chip close icon is visible using a resource id.

void
setCompoundDrawables(
    Drawable left,
    Drawable top,
    Drawable right,
    Drawable bottom
)
void
setCompoundDrawablesRelative(
    Drawable start,
    Drawable top,
    Drawable end,
    Drawable bottom
)
void
setCompoundDrawablesRelativeWithIntrinsicBounds(
    Drawable start,
    Drawable top,
    Drawable end,
    Drawable bottom
)
void
setCompoundDrawablesRelativeWithIntrinsicBounds(
    int start,
    int top,
    int end,
    int bottom
)
void
setCompoundDrawablesWithIntrinsicBounds(
    Drawable left,
    Drawable top,
    Drawable right,
    Drawable bottom
)
void
setCompoundDrawablesWithIntrinsicBounds(
    int left,
    int top,
    int right,
    int bottom
)
void
setElevation(float elevation)
void
setEllipsize(TruncateAt where)
void

Sets whether this chip should expand its bounds (if needed) to meet the minimum touch target size.

void
setGravity(int gravity)
void
setHideMotionSpec(MotionSpec hideMotionSpec)

Sets this chip's hide motion spec.

void

Sets this chip's hide motion spec using a resource id.

void
setIconEndPadding(float iconEndPadding)

Sets the end padding for this chip's icon.

void

Sets the end padding for this chip's icon using a resource id.

void
setIconStartPadding(float iconStartPadding)

Sets this chip's icon start padding.

void

Sets the start padding for this chip's icon using a resource id.

void
setLayoutDirection(int layoutDirection)
void
setLines(int lines)
void
setMaxLines(int maxLines)
void
setMaxWidth(int maxWidth)
void
setMinLines(int minLines)
void
setOnCheckedChangeListener(OnCheckedChangeListener listener)
void
setOnCloseIconClickListener(OnClickListener listener)

Register a callback to be invoked when the close icon is clicked.

void
setRippleColor(ColorStateList rippleColor)

Sets this chip's ripple color.

void

Sets this chip's ripple color using a resource id.

void

Sets the ShapeAppearanceModel that defines the shape.

void
setShowMotionSpec(MotionSpec showMotionSpec)

Sets this chip's show motion spec.

void

Sets this chip's show motion spec using a resource id.

void
setSingleLine(boolean singleLine)
void
setText(CharSequence text, BufferType type)
void
setTextAppearance(int resId)
void

Sets this chip's text appearance.

void
setTextAppearance(Context context, int resId)
void

Sets this chip's text appearance using a resource id.

void
setTextEndPadding(float textEndPadding)

Sets the end padding for this chip's text.

void

Sets the end padding for this chip's text using a resource id.

void
setTextSize(int unit, float size)
void
setTextStartPadding(float textStartPadding)

Sets the start padding for this chip's text.

void

Sets the start padding for this chip's text using a resource id.

boolean

Returns whether this chip will expand its bounds (if needed) to meet the minimum touch target size.

Protected methods

boolean
dispatchHoverEvent(MotionEvent event)
void
void
int[]
onCreateDrawableState(int extraSpace)
void
onFocusChanged(
    boolean focused,
    int direction,
    Rect previouslyFocusedRect
)

Public fields

accessibilityClassName

public CharSequence accessibilityClassName

Public constructors

Chip

public Chip(Context context)

Chip

public Chip(Context context, AttributeSet attrs)

Chip

public Chip(Context context, AttributeSet attrs, int defStyleAttr)

Public methods

dispatchKeyEvent

public boolean dispatchKeyEvent(KeyEvent event)

ensureAccessibleTouchTarget

public boolean ensureAccessibleTouchTarget(int minTargetPx)

Extends the touch target of this chip using a InsetDrawable if chip's intrinsic width / height is smaller than the minTargetPx.

Parameters
int minTargetPx

minimum touch target size in pixel

Returns
boolean

whether the background was changed

getAccessibilityClassName

public CharSequence getAccessibilityClassName()

getBackgroundDrawable

public Drawable getBackgroundDrawable()

getCheckedIcon

public Drawable getCheckedIcon()

Returns this chip's checked icon.

ref com.google.android.material.R.styleable#Chip_checkedIcon

See also
setCheckedIcon

getCheckedIconTint

public ColorStateList getCheckedIconTint()

Returns the android.content.res.ColorStateList used to tint the checked icon.

ref com.google.android.material.R.styleable#Chip_checkedIconTint

getChipBackgroundColor

public ColorStateList getChipBackgroundColor()

Returns this chip's background color.

ref com.google.android.material.R.styleable#Chip_chipBackgroundColor

getChipCornerRadius

public float getChipCornerRadius()

Returns this chip's corner radius.

ref com.google.android.material.R.styleable#Chip_chipCornerRadius

getChipDrawable

public Drawable getChipDrawable()

Returns the ChipDrawable backing this chip.

getChipEndPadding

public float getChipEndPadding()

Returns this chip's end padding.

ref com.google.android.material.R.styleable#Chip_chipEndPadding

getChipIcon

public Drawable getChipIcon()

Returns this chip's icon.

ref com.google.android.material.R.styleable#Chip_chipIcon

See also
setChipIcon

getChipIconSize

public float getChipIconSize()

Returns this chip's icon size. If a non-positive value is set, the icon drawable's width and height (up to 24dp) will be used instead.

ref com.google.android.material.R.styleable#Chip_chipIconTint

See also
setChipIconSize

getChipIconTint

public ColorStateList getChipIconTint()

Returns the android.content.res.ColorStateList used to tint the chip icon.

ref com.google.android.material.R.styleable#Chip_chipIconTint

See also
setChipIconTint

getChipMinHeight

public float getChipMinHeight()

Returns this chip's minimum height.

ref com.google.android.material.R.styleable#Chip_chipMinHeight

See also
setChipMinHeight

getChipStartPadding

public float getChipStartPadding()

Returns this chip's start padding.

ref com.google.android.material.R.styleable#Chip_chipStartPadding

getChipStrokeColor

public ColorStateList getChipStrokeColor()

Returns this chip's stroke color.

ref com.google.android.material.R.styleable#Chip_chipStrokeColor

getChipStrokeWidth

public float getChipStrokeWidth()

Returns this chip's stroke width.

ref com.google.android.material.R.styleable#Chip_chipStrokeWidth

getChipText

public CharSequence getChipText()

Returns this chip's text.

getCloseIcon

public Drawable getCloseIcon()

Returns this chip's close icon.

ref com.google.android.material.R.styleable#Chip_closeIcon

See also
setCloseIcon

getCloseIconContentDescription

public CharSequence getCloseIconContentDescription()

Returns this chip's close icon content description.

getCloseIconEndPadding

public float getCloseIconEndPadding()

Returns the end padding for this chip's close icon.

ref com.google.android.material.R.styleable#Chip_closeIconEndPadding

getCloseIconSize

public float getCloseIconSize()

Returns this chip's close icon size.

ref com.google.android.material.R.styleable#Chip_closeIconSize

See also
setCloseIconSize

getCloseIconStartPadding

public float getCloseIconStartPadding()

Returns the start padding for this chip's close icon.

ref com.google.android.material.R.styleable#Chip_closeIconStartPadding

getCloseIconTint

public ColorStateList getCloseIconTint()

Returns the tint color for this chip's close icon.

ref com.google.android.material.R.styleable#Chip_closeIconTint

See also
setCloseIconTint

getEllipsize

public TruncateAt getEllipsize()

getFocusedRect

public void getFocusedRect(Rect r)

getHideMotionSpec

public MotionSpec getHideMotionSpec()

Returns this chip's hide motion spec.

ref com.google.android.material.R.styleable#Chip_hideMotionSpec

getIconEndPadding

public float getIconEndPadding()

Returns the end padding for this chip's icon.

ref com.google.android.material.R.styleable#Chip_iconEndPadding

getIconStartPadding

public float getIconStartPadding()

Returns the start padding for this chip's icon.

ref com.google.android.material.R.styleable#Chip_iconStartPadding

getId

public abstract int getId()

getRippleColor

public ColorStateList getRippleColor()

Returns this chip's ripple color.

ref com.google.android.material.R.styleable#Chip_rippleColor

See also
setRippleColor

getShapeAppearanceModel

public ShapeAppearanceModel getShapeAppearanceModel()

Returns the ShapeAppearanceModel used for the shape definition.

This ShapeAppearanceModel can be modified to change the shape.

getShowMotionSpec

public MotionSpec getShowMotionSpec()

Returns this chip's show motion spec.

ref com.google.android.material.R.styleable#Chip_showMotionSpec

getTextEndPadding

public float getTextEndPadding()

Returns the end padding for this chip's text.

ref com.google.android.material.R.styleable#Chip_textEndPadding

getTextStartPadding

public float getTextStartPadding()

Returns the start padding for this chip's text.

ref com.google.android.material.R.styleable#Chip_textStartPadding

isCheckable

public boolean isCheckable()

Returns whether this chip is checkable.

ref com.google.android.material.R.styleable#Chip_android_checkable

See also
setCheckable

isCheckedIconEnabled

public boolean isCheckedIconEnabled()

isCheckedIconVisible

public boolean isCheckedIconVisible()

Returns whether this chip's checked icon is visible.

ref com.google.android.material.R.styleable#Chip_checkedIconVisible

isChipIconEnabled

public boolean isChipIconEnabled()

isChipIconVisible

public boolean isChipIconVisible()

Returns whether this chip's icon is visible.

ref com.google.android.material.R.styleable#Chip_chipIconVisible

isCloseIconEnabled

public boolean isCloseIconEnabled()

isCloseIconVisible

public boolean isCloseIconVisible()

Returns whether this chip's close icon is visible.

ref com.google.android.material.R.styleable#Chip_chipIconSize

onChipDrawableSizeChange

public void onChipDrawableSizeChange()

Handles a change in the ChipDrawable's size.

onHoverEvent

public boolean onHoverEvent(MotionEvent event)

onInitializeAccessibilityNodeInfo

public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)

onResolvePointerIcon

public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex)

onRtlPropertiesChanged

public void onRtlPropertiesChanged(int layoutDirection)

onTouchEvent

public boolean onTouchEvent(MotionEvent event)

performCloseIconClick

public boolean performCloseIconClick()

Call this chip's close icon click listener, if it is defined. Performs all normal actions associated with clicking: reporting accessibility event, playing a sound, etc.

Returns
boolean

True there was an assigned close icon click listener that was called, false otherwise is returned.

setAccessibilityClassName

public void setAccessibilityClassName(CharSequence className)

Sets this chip's accessibility class name.

Parameters
CharSequence className

This chip's accessibility class name.

setBackground

public void setBackground(Drawable background)

setBackgroundColor

public void setBackgroundColor(int color)

setBackgroundDrawable

public void setBackgroundDrawable(Drawable background)

setBackgroundResource

public void setBackgroundResource(int resid)

setBackgroundTintList

public void setBackgroundTintList(ColorStateList tint)

setBackgroundTintMode

public void setBackgroundTintMode(Mode tintMode)

setCheckable

public void setCheckable(boolean checkable)

Sets whether this chip is checkable.

ref com.google.android.material.R.styleable#Chip_android_checkable

Parameters
boolean checkable

Whether this chip is checkable.

setCheckableResource

public void setCheckableResource(int id)

Sets whether this chip is checkable using a resource id.

ref com.google.android.material.R.styleable#Chip_android_checkable

Parameters
int id

The resource id of this chip is checkable.

setChecked

public void setChecked(boolean checked)

setCheckedIcon

public void setCheckedIcon(Drawable checkedIcon)

Sets this chip's checked icon.

ref com.google.android.material.R.styleable#Chip_checkedIcon

Parameters
Drawable checkedIcon

This chip's checked icon.

setCheckedIconEnabled

public void setCheckedIconEnabled(boolean checkedIconEnabled)

setCheckedIconEnabledResource

public void setCheckedIconEnabledResource(int id)

setCheckedIconResource

public void setCheckedIconResource(int id)

Sets this chip's checked icon using a resource id.

ref com.google.android.material.R.styleable#Chip_checkedIcon

Parameters
int id

The resource id of this chip's checked icon.

setCheckedIconTint

public void setCheckedIconTint(ColorStateList checkedIconTint)

Sets this chip's checked icon's color tint using the specified .

ref com.google.android.material.R.styleable#Chip_checkedIconTint

Parameters
ColorStateList checkedIconTint

The tint color of this chip's checked icon.

setCheckedIconTintResource

public void setCheckedIconTintResource(int id)

Sets this chip's checked icon's color tint using a resource id.

ref com.google.android.material.R.styleable#Chip_checkedIconTint

Parameters
int id

The resource id for tinting the checked icon.

setCheckedIconVisible

public void setCheckedIconVisible(boolean checkedIconVisible)

Sets whether this chip's checked icon is visible.

ref com.google.android.material.R.styleable#Chip_checkedIconVisible

Parameters
boolean checkedIconVisible

This chip's checked icon visibility.

setCheckedIconVisible

public void setCheckedIconVisible(int id)

Sets whether this chip's checked icon is visible using a resource id.

ref com.google.android.material.R.styleable#Chip_checkedIconVisible

Parameters
int id

The resource id of this chip's check icon visibility.

setChipBackgroundColor

public void setChipBackgroundColor(ColorStateList chipBackgroundColor)

Sets this chip's background color.

ref com.google.android.material.R.styleable#Chip_chipBackgroundColor

Parameters
ColorStateList chipBackgroundColor

This chip's background color.

setChipBackgroundColorResource

public void setChipBackgroundColorResource(int id)

Sets this chip's background color using a resource id.

ref com.google.android.material.R.styleable#Chip_chipBackgroundColor

Parameters
int id

The resource id of this chip's background color.

setChipCornerRadius

public void setChipCornerRadius(float chipCornerRadius)

setChipCornerRadiusResource

public void setChipCornerRadiusResource(int id)

setChipDrawable

public void setChipDrawable(ChipDrawable drawable)

Sets the ChipDrawable backing this chip.

setChipEndPadding

public void setChipEndPadding(float chipEndPadding)

Sets this chip's end padding.

ref com.google.android.material.R.styleable#Chip_chipEndPadding

Parameters
float chipEndPadding

This chip's end padding.

setChipEndPaddingResource

public void setChipEndPaddingResource(int id)

Sets this chip's end padding using a resource id.

ref com.google.android.material.R.styleable#Chip_chipEndPadding

Parameters
int id

The resource id for this chip's end padding.

setChipIcon

public void setChipIcon(Drawable chipIcon)

Sets this chip's icon.

ref com.google.android.material.R.styleable#Chip_chipIcon

Parameters
Drawable chipIcon

drawable of this chip's icon.

setChipIconEnabled

public void setChipIconEnabled(boolean chipIconEnabled)

setChipIconEnabledResource

public void setChipIconEnabledResource(int id)

setChipIconResource

public void setChipIconResource(int id)

Sets this chip's icon using a resource id.

ref com.google.android.material.R.styleable#Chip_chipIcon

Parameters
int id

The resource id for this chip's icon.

setChipIconSize

public void setChipIconSize(float chipIconSize)

Sets this chip icon's size. If the value is zero or negative, the icon drawable's width and height (up to 24dp) will be used instead.

ref com.google.android.material.R.styleable#Chip_chipIconSize

Parameters
float chipIconSize

This chip's icon size.

setChipIconSizeResource

public void setChipIconSizeResource(int id)

Sets this chip icon's size using a resource id. If the value is zero or negative, the icon drawable's width and height (up to 24dp) will be used instead.

ref com.google.android.material.R.styleable#Chip_chipIconSize

Parameters
int id

The resource id of this chip's icon size.

setChipIconTint

public void setChipIconTint(ColorStateList chipIconTint)

Sets this chip icon's color tint using the specified .

ref com.google.android.material.R.styleable#Chip_chipIconTint

Parameters
ColorStateList chipIconTint

The tint color of this chip's icon.

setChipIconTintResource

public void setChipIconTintResource(int id)

Sets this chip icon's color tint using a resource id.

ref com.google.android.material.R.styleable#Chip_chipIconTint

Parameters
int id

The resource id for tinting the chip icon.

setChipIconVisible

public void setChipIconVisible(boolean chipIconVisible)

Sets whether this chip's icon is visible.

ref com.google.android.material.R.styleable#Chip_chipIconIsVisible

Parameters
boolean chipIconVisible

The visibility of this chip's icon.

setChipIconVisible

public void setChipIconVisible(int id)

Sets the visibility of this chip's icon using a resource id.

ref com.google.android.material.R.styleable#Chip_chipIconVisible

Parameters
int id

The resource id for the visibility of this chip's icon.

setChipMinHeight

public void setChipMinHeight(float minHeight)

Sets this chip's minimum height.

ref com.google.android.material.R.styleable#Chip_chipMinHeight

Parameters
float minHeight

This chip's minimum height.

setChipMinHeightResource

public void setChipMinHeightResource(int id)

Sets this chip's minimum height using a resource id.

ref com.google.android.material.R.styleable#Chip_chipMinHeight

Parameters
int id

The resource id of this chip's minimum height.

setChipStartPadding

public void setChipStartPadding(float chipStartPadding)

Sets this chip's start padding.

ref com.google.android.material.R.styleable#Chip_chipStartPadding

Parameters
float chipStartPadding

This chip's start padding.

setChipStartPaddingResource

public void setChipStartPaddingResource(int id)

Sets this chip's start padding using a resource id.

ref com.google.android.material.R.styleable#Chip_chipStartPadding

Parameters
int id

The resource id of this chip's start padding.

setChipStrokeColor

public void setChipStrokeColor(ColorStateList chipStrokeColor)

Sets this chip's stroke color.

ref com.google.android.material.R.styleable#Chip_chipStrokeColor

Parameters
ColorStateList chipStrokeColor

This chip's stroke color.

setChipStrokeColorResource

public void setChipStrokeColorResource(int id)

Sets this chip's stroke color using a resource id.

ref com.google.android.material.R.styleable#Chip_chipStrokeColor

Parameters
int id

The resource id of this chip's stroke color.

setChipStrokeWidth

public void setChipStrokeWidth(float chipStrokeWidth)

Sets this chip's stroke width.

ref com.google.android.material.R.styleable#Chip_chipStrokeWidth

Parameters
float chipStrokeWidth

This chip's stroke width.

setChipStrokeWidthResource

public void setChipStrokeWidthResource(int id)

Sets this chip's stroke width using a resource id.

ref com.google.android.material.R.styleable#Chip_chipStrokeWidth

Parameters
int id

The resource id of this chip's stroke width.

setChipText

public void setChipText(CharSequence chipText)

setChipTextResource

public void setChipTextResource(int id)

setCloseIcon

public void setCloseIcon(Drawable closeIcon)

Sets this chip's close icon.

ref com.google.android.material.R.styleable#Chip_closeIcon

Parameters
Drawable closeIcon

This chip's close icon.

setCloseIconContentDescription

public void setCloseIconContentDescription(
    CharSequence closeIconContentDescription
)

Sets the content description for this chip's close icon.

Parameters
CharSequence closeIconContentDescription

The content description for this chip's close icon.

setCloseIconEnabled

public void setCloseIconEnabled(boolean closeIconEnabled)

setCloseIconEnabledResource

public void setCloseIconEnabledResource(int id)

setCloseIconEndPadding

public void setCloseIconEndPadding(float closeIconEndPadding)

Sets the end padding for this chip's close icon.

ref com.google.android.material.R.styleable#Chip_closeIconEndPadding

Parameters
float closeIconEndPadding

The end padding of this chip's close icon.

setCloseIconEndPaddingResource

public void setCloseIconEndPaddingResource(int id)

Sets the end padding for this chip's close icon using a resource id.

ref com.google.android.material.R.styleable#Chip_closeIconEndPadding

Parameters
int id

The resource id for the end padding of this chip's close icon.

setCloseIconResource

public void setCloseIconResource(int id)

Sets this chip's close icon using a resource id.

ref com.google.android.material.R.styleable#Chip_closeIcon

Parameters
int id

The resource id of this chip's close icon.

setCloseIconSize

public void setCloseIconSize(float closeIconSize)

Sets this chip's close icon size.

ref com.google.android.material.R.styleable#Chip_closeIconSize

Parameters
float closeIconSize

This chip's close icon size.

setCloseIconSizeResource

public void setCloseIconSizeResource(int id)

Sets this chip's close icon size using a resource id.

ref com.google.android.material.R.styleable#Chip_closeIconSize

Parameters
int id

The resource id of this chip's close icon size.

setCloseIconStartPadding

public void setCloseIconStartPadding(float closeIconStartPadding)

Sets the start padding for this chip's close icon.

ref com.google.android.material.R.styleable#Chip_closeIconStartPadding

Parameters
float closeIconStartPadding

The start padding of this chip's close icon.

setCloseIconStartPaddingResource

public void setCloseIconStartPaddingResource(int id)

Sets the start padding for this chip's close icon using a resource id.

ref com.google.android.material.R.styleable#Chip_closeIconStartPadding

Parameters
int id

The resource id for the start padding of this chip's close icon.

setCloseIconTint

public void setCloseIconTint(ColorStateList closeIconTint)

Sets the tint color for this chip's close icon.

ref com.google.android.material.R.styleable#Chip_closeIconTint

Parameters
ColorStateList closeIconTint

This chip's close icon tint.

setCloseIconTintResource

public void setCloseIconTintResource(int id)

Sets the tint color for this chip's close icon using a resource id.

ref com.google.android.material.R.styleable#Chip_closeIconTint

Parameters
int id

The resource id of this chip's close icon tint.

setCloseIconVisible

public void setCloseIconVisible(boolean closeIconVisible)

Sets whether this chip close icon is visible.

ref com.google.android.material.R.styleable#Chip_closeIconVisible

Parameters
boolean closeIconVisible

This chip's close icon visibility.

setCloseIconVisible

public void setCloseIconVisible(int id)

Sets whether this chip close icon is visible using a resource id.

ref com.google.android.material.R.styleable#Chip_closeIconVisible

Parameters
int id

The resource id of this chip's close icon visibility.

setCompoundDrawables

public void setCompoundDrawables(
    Drawable left,
    Drawable top,
    Drawable right,
    Drawable bottom
)

setCompoundDrawablesRelative

public void setCompoundDrawablesRelative(
    Drawable start,
    Drawable top,
    Drawable end,
    Drawable bottom
)

setCompoundDrawablesRelativeWithIntrinsicBounds

public void setCompoundDrawablesRelativeWithIntrinsicBounds(
    Drawable start,
    Drawable top,
    Drawable end,
    Drawable bottom
)

setCompoundDrawablesRelativeWithIntrinsicBounds

public void setCompoundDrawablesRelativeWithIntrinsicBounds(
    int start,
    int top,
    int end,
    int bottom
)

setCompoundDrawablesWithIntrinsicBounds

public void setCompoundDrawablesWithIntrinsicBounds(
    Drawable left,
    Drawable top,
    Drawable right,
    Drawable bottom
)

setCompoundDrawablesWithIntrinsicBounds

public void setCompoundDrawablesWithIntrinsicBounds(
    int left,
    int top,
    int right,
    int bottom
)

setElevation

public void setElevation(float elevation)

setEllipsize

public void setEllipsize(TruncateAt where)

setEnsureMinTouchTargetSize

public void setEnsureMinTouchTargetSize(boolean flag)

Sets whether this chip should expand its bounds (if needed) to meet the minimum touch target size.

ref com.google.android.material.R.styleable#Chip_ensureMinTouchTargetSize

Parameters
boolean flag

Whether this chip should meet the min touch target size.

setGravity

public void setGravity(int gravity)

setHideMotionSpec

public void setHideMotionSpec(MotionSpec hideMotionSpec)

Sets this chip's hide motion spec.

ref com.google.android.material.R.styleable#Chip_hideMotionSpec

Parameters
MotionSpec hideMotionSpec

This chip's hide motion spec.

setHideMotionSpecResource

public void setHideMotionSpecResource(int id)

Sets this chip's hide motion spec using a resource id.

ref com.google.android.material.R.styleable#Chip_hideMotionSpec

Parameters
int id

The resource id of this chip's hide motion spec.

setIconEndPadding

public void setIconEndPadding(float iconEndPadding)

Sets the end padding for this chip's icon.

ref com.google.android.material.R.styleable#Chip_iconEndPadding

Parameters
float iconEndPadding

The end padding of this chip's icon.

setIconEndPaddingResource

public void setIconEndPaddingResource(int id)

Sets the end padding for this chip's icon using a resource id.

ref com.google.android.material.R.styleable#Chip_iconEndPadding

Parameters
int id

The resource id for the end padding of this chip's icon.

setIconStartPadding

public void setIconStartPadding(float iconStartPadding)

Sets this chip's icon start padding.

ref com.google.android.material.R.styleable#Chip_iconStartPadding

Parameters
float iconStartPadding

The start padding of this chip's icon.

setIconStartPaddingResource

public void setIconStartPaddingResource(int id)

Sets the start padding for this chip's icon using a resource id.

ref com.google.android.material.R.styleable#Chip_iconStartPadding

Parameters
int id

The resource id for the start padding of this chip's icon.

setLayoutDirection

public void setLayoutDirection(int layoutDirection)

setLines

public void setLines(int lines)

setMaxLines

public void setMaxLines(int maxLines)

setMaxWidth

public void setMaxWidth(int maxWidth)

setMinLines

public void setMinLines(int minLines)

setOnCheckedChangeListener

public void setOnCheckedChangeListener(OnCheckedChangeListener listener)

setOnCloseIconClickListener

public void setOnCloseIconClickListener(OnClickListener listener)

Register a callback to be invoked when the close icon is clicked.

setRippleColor

public void setRippleColor(ColorStateList rippleColor)

Sets this chip's ripple color.

ref com.google.android.material.R.styleable#Chip_rippleColor

Parameters
ColorStateList rippleColor

This chip's ripple color.

setRippleColorResource

public void setRippleColorResource(int id)

Sets this chip's ripple color using a resource id.

ref com.google.android.material.R.styleable#Chip_rippleColor

Parameters
int id

The resource id of this chip's ripple color.

setShapeAppearanceModel

public void setShapeAppearanceModel(ShapeAppearanceModel shapeAppearanceModel)

Sets the ShapeAppearanceModel that defines the shape.

setShowMotionSpec

public void setShowMotionSpec(MotionSpec showMotionSpec)

Sets this chip's show motion spec.

ref com.google.android.material.R.styleable#Chip_showMotionSpec

Parameters
MotionSpec showMotionSpec

This chip's show motion spec.

setShowMotionSpecResource

public void setShowMotionSpecResource(int id)

Sets this chip's show motion spec using a resource id.

ref com.google.android.material.R.styleable#Chip_showMotionSpec

Parameters
int id

The resource id of this chip's show motion spec.

setSingleLine

public void setSingleLine(boolean singleLine)

setText

public void setText(CharSequence text, BufferType type)

setTextAppearance

public void setTextAppearance(int resId)

setTextAppearance

public void setTextAppearance(TextAppearance textAppearance)

Sets this chip's text appearance.

ref com.google.android.material.R.styleable#Chip_android_textAppearance

Parameters
TextAppearance textAppearance

This chip's text appearance.

setTextAppearance

public void setTextAppearance(Context context, int resId)

setTextAppearanceResource

public void setTextAppearanceResource(int id)

Sets this chip's text appearance using a resource id.

ref com.google.android.material.R.styleable#Chip_android_textAppearance

Parameters
int id

The resource id of this chip's text appearance.

setTextEndPadding

public void setTextEndPadding(float textEndPadding)

Sets the end padding for this chip's text.

ref com.google.android.material.R.styleable#Chip_textStartPadding

Parameters
float textEndPadding

The end padding of this chip's text.

setTextEndPaddingResource

public void setTextEndPaddingResource(int id)

Sets the end padding for this chip's text using a resource id.

ref com.google.android.material.R.styleable#Chip_textEndPadding

Parameters
int id

The resource id for the end padding of this chip's text.

setTextSize

public void setTextSize(int unit, float size)

setTextStartPadding

public void setTextStartPadding(float textStartPadding)

Sets the start padding for this chip's text.

ref com.google.android.material.R.styleable#Chip_textStartPadding

Parameters
float textStartPadding

The start padding of this chip's text.

setTextStartPaddingResource

public void setTextStartPaddingResource(int id)

Sets the start padding for this chip's text using a resource id.

ref com.google.android.material.R.styleable#Chip_textStartPadding

Parameters
int id

The resource id for the start padding of this chip's text.

shouldEnsureMinTouchTargetSize

public boolean shouldEnsureMinTouchTargetSize()

Returns whether this chip will expand its bounds (if needed) to meet the minimum touch target size.

ref com.google.android.material.R.styleable#Chip_ensureMinTouchTargetSize

Protected methods

dispatchHoverEvent

protected boolean dispatchHoverEvent(MotionEvent event)

drawableStateChanged

protected void drawableStateChanged()

onAttachedToWindow

protected void onAttachedToWindow()

onCreateDrawableState

protected int[] onCreateDrawableState(int extraSpace)

onFocusChanged

protected void onFocusChanged(
    boolean focused,
    int direction,
    Rect previouslyFocusedRect
)