public class ChipSpan extends android.text.style.ImageSpan implements Chip
(chip vertical spacing / 2)
----------------------------------------------------------
| |
(left margin) | (padding edge) text (padding between image) icon | (right margin)
| |
----------------------------------------------------------
(chip vertical spacing / 2)
For chips with the icon on the left (see setShowIconOnLeft(boolean)):
(chip vertical spacing / 2)
----------------------------------------------------------
| |
(left margin) | icon (padding between image) text (padding edge) | (right margin)
| |
----------------------------------------------------------
(chip vertical spacing / 2)
| Constructor and Description |
|---|
ChipSpan(android.content.Context context,
java.lang.CharSequence text,
android.graphics.drawable.Drawable icon,
java.lang.Object data)
Constructs a new ChipSpan.
|
ChipSpan(android.content.Context context,
ChipSpan chipSpan)
Copy constructor to recreate a ChipSpan from an existing one
|
| Modifier and Type | Method and Description |
|---|---|
void |
draw(android.graphics.Canvas canvas,
java.lang.CharSequence text,
int start,
int end,
float x,
int top,
int y,
int bottom,
android.graphics.Paint paint) |
java.lang.Object |
getData() |
int |
getSize(android.graphics.Paint paint,
java.lang.CharSequence text,
int start,
int end,
android.graphics.Paint.FontMetricsInt fm) |
java.lang.CharSequence |
getText() |
int |
getWidth() |
void |
invalidateCachedSize() |
void |
setBackgroundColor(android.content.res.ColorStateList backgroundColor)
Sets the background color.
|
void |
setChipHeight(int chipHeight)
Sets the height of the chip.
|
void |
setChipVerticalSpacing(int chipVerticalSpacing)
Sets the vertical spacing to include in between chips.
|
void |
setCornerRadius(int cornerRadius)
Sets the chip background corner radius.
|
void |
setIconBackgroundColor(int iconBackgroundColor)
Sets the icon background color.
|
void |
setLeftMargin(int leftMarginPx)
Sets the left margin.
|
void |
setMaxAvailableWidth(int maxAvailableWidth) |
void |
setRightMargin(int rightMarginPx)
Sets the right margin.
|
void |
setShowIconOnLeft(boolean showIconOnLeft)
Sets where the icon (if an icon was provided in the constructor) will appear.
|
void |
setState(int[] stateSet)
Sets the UI state.
|
void |
setTextColor(int color)
Sets the color for the chip's text.
|
void |
setTextSize(int size)
Sets the font size for the chip's text.
|
java.lang.String |
toString() |
public ChipSpan(android.content.Context context,
java.lang.CharSequence text,
android.graphics.drawable.Drawable icon,
java.lang.Object data)
context - a Context that will be used to retrieve default configurations from resource filestext - the text for the ChipSpan to displayicon - an optional icon (can be null) for the ChipSpan to displaypublic ChipSpan(android.content.Context context,
ChipSpan chipSpan)
context - a Context that will be used to retrieve default configurations from resource fileschipSpan - the ChipSpan to copypublic java.lang.Object getData()
public void setChipHeight(int chipHeight)
setChipVerticalSpacing(int)).
The background of the chip will fill the full height provided here. If this method is never called, the chip will have the height of one full line
of text by default. If -1 is passed here, the chip will revert to this default behavior.chipHeight - the height to set in pixelspublic void setChipVerticalSpacing(int chipVerticalSpacing)
setChipHeight(int)). If a
height is not specified in that method, the value set here will be ignored.chipVerticalSpacing - the vertical spacing to set in pixelspublic void setTextSize(int size)
-1 is passed here, the chip will revert to this default behavior.size - the font size to set in pixelspublic void setTextColor(int color)
color - the color to set (as a hexadecimal number in the form 0xAARRGGBB)public void setShowIconOnLeft(boolean showIconOnLeft)
showIconOnLeft - if true, the icon will appear on the left, otherwise the icon will appear on the rightpublic void setLeftMargin(int leftMarginPx)
leftMarginPx - the left margin to set in pixelspublic void setRightMargin(int rightMarginPx)
rightMarginPx - the right margin to set in pixelspublic void setBackgroundColor(android.content.res.ColorStateList backgroundColor)
ColorStateList is shown you can call setState(int[]).
Passing null here will cause the chip to revert to it's default background.backgroundColor - a ColorStateList containing backgrounds for different states.setState(int[])public void setCornerRadius(int cornerRadius)
cornerRadius - The corner radius value, in pixels.public void setIconBackgroundColor(int iconBackgroundColor)
ChipSpan(Context, CharSequence, Drawable, Object) constructor}iconBackgroundColor - the icon background color to set (as a hexadecimal number in the form 0xAARRGGBB)public void setMaxAvailableWidth(int maxAvailableWidth)
public void setState(int[] stateSet)
setState in interface ChipstateSet - one of the state constants in ViewsetBackgroundColor(ColorStateList)public java.lang.CharSequence getText()
public int getWidth()
public int getSize(android.graphics.Paint paint,
java.lang.CharSequence text,
int start,
int end,
android.graphics.Paint.FontMetricsInt fm)
getSize in class android.text.style.DynamicDrawableSpanpublic void invalidateCachedSize()
public void draw(android.graphics.Canvas canvas,
java.lang.CharSequence text,
int start,
int end,
float x,
int top,
int y,
int bottom,
android.graphics.Paint paint)
draw in class android.text.style.DynamicDrawableSpanpublic java.lang.String toString()
toString in class java.lang.Object