public class NinePatchDrawable extends Drawable
For more information about how to use a NinePatchDrawable, read the Canvas and Drawables developer guide. For information about creating a NinePatch image file using the draw9patch tool, see the Draw 9-patch tool guide.
Drawable.Callback, Drawable.ConstantState
Constructor and Description |
---|
NinePatchDrawable(Bitmap bitmap,
byte[] chunk,
Rect padding,
String srcName)
Deprecated.
Use
NinePatchDrawable(Resources, Bitmap, byte[], Rect, String)
to ensure that the drawable has correctly set its target density. |
NinePatchDrawable(NinePatch patch)
Deprecated.
Use
NinePatchDrawable(Resources, NinePatch)
to ensure that the drawable has correctly set its target
density. |
NinePatchDrawable(Resources res,
Bitmap bitmap,
byte[] chunk,
Rect padding,
Rect opticalInsets,
String srcName)
Create drawable from raw nine-patch data, setting initial target density
based on the display metrics of the resources.
|
NinePatchDrawable(Resources res,
Bitmap bitmap,
byte[] chunk,
Rect padding,
String srcName)
Create drawable from raw nine-patch data, setting initial target density
based on the display metrics of the resources.
|
NinePatchDrawable(Resources res,
NinePatch patch)
Create drawable from existing nine-patch, setting initial target density
based on the display metrics of the resources.
|
Modifier and Type | Method and Description |
---|---|
void |
applyTheme(Resources.Theme t)
Applies the specified theme to this Drawable and its children.
|
boolean |
canApplyTheme() |
void |
clearMutated()
Clears the mutated state, allowing this drawable to be cached and
mutated again.
|
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()
Gets the current alpha value for the drawable. 0 means fully transparent,
255 means fully opaque.
|
int |
getChangingConfigurations()
Return a mask of the configuration parameters for which this drawable
may change, requiring that it be re-created.
|
Drawable.ConstantState |
getConstantState()
Return a
Drawable.ConstantState instance that holds the shared state of this Drawable. |
int |
getIntrinsicHeight()
Returns the drawable's intrinsic height.
|
int |
getIntrinsicWidth()
Returns the drawable's intrinsic width.
|
int |
getOpacity()
Return the opacity/transparency of this Drawable.
|
Insets |
getOpticalInsets()
Return in insets the layout insets suggested by this Drawable for use with alignment
operations during layout.
|
void |
getOutline(Outline outline)
Called to get the drawable to populate the Outline that defines its drawing area.
|
boolean |
getPadding(Rect padding)
Return in padding the insets suggested by this Drawable for placing
content inside the drawable's bounds.
|
Paint |
getPaint() |
Region |
getTransparentRegion()
Returns a Region representing the part of the Drawable that is completely
transparent.
|
void |
inflate(Resources r,
XmlPullParser parser,
AttributeSet attrs,
Resources.Theme theme)
Inflate this Drawable from an XML resource optionally styled by a theme.
|
boolean |
isAutoMirrored()
Tells if this Drawable will be automatically mirrored when its layout direction is RTL
right-to-left.
|
boolean |
isFilterBitmap() |
boolean |
isStateful()
Indicates whether this drawable will change its appearance based on
state.
|
Drawable |
mutate()
Make this drawable mutable.
|
protected boolean |
onStateChange(int[] stateSet)
Override this in your subclass to change appearance if you recognize the
specified state.
|
void |
setAlpha(int alpha)
Specify an alpha value for the drawable. 0 means fully transparent, and
255 means fully opaque.
|
void |
setAutoMirrored(boolean mirrored)
Set whether this Drawable is automatically mirrored when its layout direction is RTL
(right-to left).
|
void |
setColorFilter(ColorFilter colorFilter)
Specify an optional color filter for the drawable.
|
void |
setDither(boolean dither)
Set to true to have the drawable dither its colors when drawn to a
device with fewer than 8-bits per color component.
|
void |
setFilterBitmap(boolean filter)
Set to true to have the drawable filter its bitmaps with bilinear
sampling when they are scaled or rotated.
|
void |
setTargetDensity(Canvas canvas)
Set the density scale at which this drawable will be rendered.
|
void |
setTargetDensity(DisplayMetrics metrics)
Set the density scale at which this drawable will be rendered.
|
void |
setTargetDensity(int density)
Set the density at which this drawable will be rendered.
|
void |
setTintList(ColorStateList tint)
Specifies tint color for this drawable as a color state list.
|
void |
setTintMode(PorterDuff.Mode tintMode)
Specifies a tint blending mode for this drawable.
|
clearColorFilter, copyBounds, copyBounds, createFromPath, createFromResourceStream, createFromResourceStream, createFromStream, createFromXml, createFromXml, createFromXmlInner, createFromXmlInner, getBounds, getCallback, getColorFilter, getCurrent, getDirtyBounds, getHotspotBounds, getLayoutDirection, getLevel, getMinimumHeight, getMinimumWidth, getState, inflate, invalidateSelf, isProjected, isVisible, jumpToCurrentState, obtainAttributes, onBoundsChange, onLayoutDirectionChanged, onLevelChange, parseTintMode, resolveOpacity, scheduleSelf, setBounds, setBounds, setCallback, setChangingConfigurations, setColorFilter, setHotspot, setHotspotBounds, setLayoutDirection, setLevel, setState, setTint, setVisible, setXfermode, unscheduleSelf
@Deprecated public NinePatchDrawable(Bitmap bitmap, byte[] chunk, Rect padding, String srcName)
NinePatchDrawable(Resources, Bitmap, byte[], Rect, String)
to ensure that the drawable has correctly set its target density.public NinePatchDrawable(Resources res, Bitmap bitmap, byte[] chunk, Rect padding, String srcName)
public NinePatchDrawable(Resources res, Bitmap bitmap, byte[] chunk, Rect padding, Rect opticalInsets, String srcName)
@Deprecated public NinePatchDrawable(NinePatch patch)
NinePatchDrawable(Resources, NinePatch)
to ensure that the drawable has correctly set its target
density.public void setTargetDensity(Canvas canvas)
canvas
- The Canvas from which the density scale must be obtained.Bitmap.setDensity(int)
,
Bitmap.getDensity()
public void setTargetDensity(DisplayMetrics metrics)
metrics
- The DisplayMetrics indicating the density scale for this drawable.Bitmap.setDensity(int)
,
Bitmap.getDensity()
public void setTargetDensity(int density)
density
- The density scale for this drawable.Bitmap.setDensity(int)
,
Bitmap.getDensity()
public void draw(Canvas canvas)
Drawable
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
ActivityInfo
.ActivityInfo
public boolean getPadding(Rect padding)
Drawable
getPadding
in class Drawable
public void getOutline(Outline outline)
Drawable
This method is called by the default ViewOutlineProvider
to define
the outline of the View.
The default behavior defines the outline to be the bounding rectangle of 0 alpha. Subclasses that wish to convey a different shape or alpha value must override this method.
getOutline
in class Drawable
View.setOutlineProvider(android.view.ViewOutlineProvider)
public Insets getOpticalInsets()
Drawable
getOpticalInsets
in class Drawable
public void setAlpha(int alpha)
Drawable
public int getAlpha()
Drawable
public void setColorFilter(ColorFilter colorFilter)
Drawable
If a Drawable has a ColorFilter, each output pixel of the Drawable's drawing contents will be modified by the color filter before it is blended onto the render target of a Canvas.
Pass null
to remove any existing color filter.
Note: Setting a non-null
color
filter disables tint
.
setColorFilter
in class Drawable
colorFilter
- The color filter to apply, or null
to remove the
existing color filterpublic void setTintList(ColorStateList tint)
Drawable
A Drawable's drawing content will be blended together with its tint
before it is drawn to the screen. This functions similarly to
Drawable.setColorFilter(int, PorterDuff.Mode)
.
Note: Setting a color filter via
Drawable.setColorFilter(ColorFilter)
or
Drawable.setColorFilter(int, PorterDuff.Mode)
overrides tint.
setTintList
in class Drawable
tint
- Color state list to use for tinting this drawable, or
null
to clear the tintDrawable.setTint(int)
,
Drawable.setTintMode(PorterDuff.Mode)
public void setTintMode(PorterDuff.Mode tintMode)
Drawable
Defines how this drawable's tint color should be blended into the drawable
before it is drawn to screen. Default tint mode is PorterDuff.Mode#SRC_IN
.
Note: Setting a color filter via
Drawable.setColorFilter(ColorFilter)
or
Drawable.setColorFilter(int, PorterDuff.Mode)
overrides tint.
setTintMode
in class Drawable
tintMode
- A Porter-Duff blending modeDrawable.setTint(int)
,
Drawable.setTintList(ColorStateList)
public void setDither(boolean dither)
Drawable
setDither
in class Drawable
Paint.setDither(boolean);
public void setAutoMirrored(boolean mirrored)
Drawable
LayoutDirection
.setAutoMirrored
in class Drawable
mirrored
- Set to true if the Drawable should be mirrored, false if not.public boolean isAutoMirrored()
Drawable
LayoutDirection
.isAutoMirrored
in class Drawable
public void setFilterBitmap(boolean filter)
Drawable
This can improve appearance when bitmaps are rotated. If the drawable does not use bitmaps, this call is ignored.
setFilterBitmap
in class Drawable
Drawable.isFilterBitmap()
,
Paint.setFilterBitmap(boolean);
public boolean isFilterBitmap()
isFilterBitmap
in class Drawable
Drawable.setFilterBitmap(boolean)
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme) throws XmlPullParserException, IOException
Drawable
inflate
in class Drawable
r
- Resources used to resolve attribute valuesparser
- XML parser from which to inflate this Drawableattrs
- Base set of attribute valuestheme
- Theme to apply, may be nullXmlPullParserException
IOException
public void applyTheme(Resources.Theme t)
Drawable
applyTheme
in class Drawable
t
- the theme to applypublic boolean canApplyTheme()
canApplyTheme
in class Drawable
public Paint getPaint()
public int getIntrinsicWidth()
Drawable
Intrinsic width is the width at which the drawable would like to be laid out, including any inherent padding. If the drawable has no intrinsic width, such as a solid color, this method returns -1.
getIntrinsicWidth
in class Drawable
public int getIntrinsicHeight()
Drawable
Intrinsic height is the height at which the drawable would like to be laid out, including any inherent padding. If the drawable has no intrinsic height, such as a solid color, this method returns -1.
getIntrinsicHeight
in class Drawable
public int getOpacity()
Drawable
PixelFormat
:
PixelFormat.UNKNOWN
,
PixelFormat.TRANSLUCENT
,
PixelFormat.TRANSPARENT
, or
PixelFormat.OPAQUE
.
An OPAQUE drawable is one that draws all all content within its bounds, completely covering anything behind the drawable. A TRANSPARENT drawable is one that draws nothing within its bounds, allowing everything behind it to show through. A TRANSLUCENT drawable is a drawable in any other state, where the drawable will draw some, but not all, of the content within its bounds and at least some content behind the drawable will be visible. If the visibility of the drawable's contents cannot be determined, the safest/best return value is TRANSLUCENT.
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 necessarily 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. Some subclasses,
such as BitmapDrawable
, ColorDrawable
, and GradientDrawable
,
do account for the value of Drawable.setAlpha(int)
, but the general behavior is dependent
upon the implementation of the subclass.
getOpacity
in class Drawable
PixelFormat
public Region getTransparentRegion()
Drawable
getTransparentRegion
in class Drawable
public Drawable.ConstantState getConstantState()
Drawable
Drawable.ConstantState
instance that holds the shared state of this Drawable.getConstantState
in class Drawable
Drawable.ConstantState
,
Drawable.mutate()
public Drawable mutate()
Drawable
mutate
in class Drawable
Drawable.ConstantState
,
Drawable.getConstantState()
public void clearMutated()
Drawable
This is hidden because only framework drawables can be cached, so custom drawables don't need to support constant state, mutate(), or clearMutated().
clearMutated
in class Drawable
protected boolean onStateChange(int[] stateSet)
Drawable
onStateChange
in class Drawable
public boolean isStateful()
Drawable
isStateful
in class Drawable
Drawable.setState(int[])