public class ColorDrawable extends Drawable
It can be defined in an XML file with the <color>
element.
Drawable.Callback, Drawable.ConstantState
Constructor and Description |
---|
ColorDrawable()
Creates a new black ColorDrawable.
|
ColorDrawable(int color)
Creates a new ColorDrawable with the specified color.
|
Modifier and Type | Method and Description |
---|---|
void |
draw(Canvas canvas)
Draw in its bounds (set via setBounds) respecting optional effects such
as alpha (set via setAlpha) and color filter (set via setColorFilter).
|
int |
getAlpha()
Returns the alpha value of this drawable's color.
|
int |
getChangingConfigurations()
Return a mask of the configuration parameters for which this drawable
may change, requiring that it be re-created.
|
int |
getColor()
Gets the drawable's color value.
|
Drawable.ConstantState |
getConstantState()
Return a
Drawable.ConstantState instance that holds the shared state of this Drawable. |
int |
getOpacity()
Return the opacity/transparency of this Drawable.
|
void |
inflate(Resources r,
XmlPullParser parser,
AttributeSet attrs)
Inflate this Drawable from an XML resource.
|
Drawable |
mutate()
A mutable BitmapDrawable still shares its Bitmap with any other Drawable
that comes from the same resource.
|
void |
setAlpha(int alpha)
Sets the color's alpha value.
|
void |
setColor(int color)
Sets the drawable's color value.
|
void |
setColorFilter(ColorFilter colorFilter)
Setting a color filter on a ColorDrawable has no effect.
|
clearColorFilter, copyBounds, copyBounds, createFromPath, createFromResourceStream, createFromResourceStream, createFromStream, createFromXml, createFromXmlInner, getBounds, getCallback, getCurrent, getIntrinsicHeight, getIntrinsicWidth, getLayoutDirection, getLayoutInsets, getLevel, getMinimumHeight, getMinimumWidth, getPadding, getState, getTransparentRegion, invalidateSelf, isStateful, isVisible, jumpToCurrentState, onBoundsChange, onLevelChange, onStateChange, resolveOpacity, scheduleSelf, setBounds, setBounds, setCallback, setChangingConfigurations, setColorFilter, setDither, setFilterBitmap, setLayoutDirection, setLevel, setState, setVisible, unscheduleSelf
public ColorDrawable()
public ColorDrawable(int color)
color
- The color to draw.public int getChangingConfigurations()
Drawable
Drawable.setChangingConfigurations(int)
or 0 by default. Subclasses
may extend this to or in the changing configurations of any other
drawables they hold.getChangingConfigurations
in class Drawable
Configuration
.Configuration
public Drawable mutate()
mutate
in class Drawable
Drawable.ConstantState
,
Drawable.getConstantState()
public void draw(Canvas canvas)
Drawable
public int getColor()
public void setColor(int color)
setAlpha(int)
on this object, which side-affected the underlying color.color
- The color to draw.public int getAlpha()
public void setAlpha(int alpha)
public void setColorFilter(ColorFilter colorFilter)
setColorFilter
in class Drawable
colorFilter
- Ignore.public int getOpacity()
Drawable
PixelFormat
:
PixelFormat.UNKNOWN
,
PixelFormat.TRANSLUCENT
,
PixelFormat.TRANSPARENT
, or
PixelFormat.OPAQUE
.
Generally a Drawable should be as conservative as possible with the
value it returns. For example, if it contains multiple child drawables
and only shows one of them at a time, if only one of the children is
TRANSLUCENT and the others are OPAQUE then TRANSLUCENT should be
returned. You can use the method Drawable.resolveOpacity(int, int)
to perform a
standard reduction of two opacities to the appropriate single output.
Note that the returned value does not take into account a
custom alpha or color filter that has been applied by the client through
the Drawable.setAlpha(int)
or Drawable.setColorFilter(android.graphics.ColorFilter)
methods.
getOpacity
in class Drawable
PixelFormat
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException
Drawable
inflate
in class Drawable
XmlPullParserException
IOException
public Drawable.ConstantState getConstantState()
Drawable
Drawable.ConstantState
instance that holds the shared state of this Drawable.
qgetConstantState
in class Drawable
Drawable.ConstantState
,
Drawable.mutate()