NinePatchDrawable

open class NinePatchDrawable : Drawable
kotlin.Any
   ↳ android.graphics.drawable.Drawable
   ↳ android.graphics.drawable.NinePatchDrawable

A resizeable bitmap, with stretchable areas that you define. This type of image is defined in a .png file with a special format. Developer Guides

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.

Summary

Public constructors
<init>(bitmap: Bitmap!, chunk: ByteArray!, padding: Rect!, srcName: String!)

Use #NinePatchDrawable(Resources, Bitmap, byte[], Rect, String) to ensure that the drawable has correctly set its target density.

<init>(res: Resources!, bitmap: Bitmap!, chunk: ByteArray!, padding: Rect!, srcName: String!)

Create drawable from raw nine-patch data, setting initial target density based on the display metrics of the resources.

<init>(patch: NinePatch)

Use #NinePatchDrawable(Resources, NinePatch) to ensure that the drawable has correctly set its target density.

<init>(res: Resources?, patch: NinePatch)

Create drawable from existing nine-patch, setting initial target density based on the display metrics of the resources.

Public methods
open Boolean

Requires API level 21 (Android 5.0, Lollipop) Requires API level 21 (Android 5.0, Lollipop)

open Unit
draw(canvas: Canvas)

open Int

Gets the current alpha value for the drawable.

open Unit
setAlpha(alpha: Int)

open Unit

Set whether this Drawable is automatically mirrored when its layout direction is RTL (right-to left).

open Int

open Unit

Specifies a tint blending mode for this drawable.

open Unit

Applies the specified theme to this Drawable and its children.

open Unit
inflate(r: Resources, parser: XmlPullParser, attrs: AttributeSet, theme: Resources.Theme?)

Inflate this Drawable from an XML resource optionally styled by a theme.

open Unit
setDither(dither: Boolean)

open Unit

open Int

open Unit
getOutline(outline: Outline)

Called to get the drawable to populate the Outline that defines its drawing area.

open Drawable

Make this drawable mutable.

open Int

open Int

Return a mask of the configuration parameters for which this drawable may change, requiring that it be re-created.

open Boolean

open Unit

Set the density scale at which this drawable will be rendered.

open Unit

Set the density scale at which this drawable will be rendered.

open Unit

Set the density at which this drawable will be rendered.

open Paint

open Unit
setColorFilter(colorFilter: ColorFilter?)

Specify an optional color filter for the drawable.

open Region?

open Drawable.ConstantState?

open Boolean
getPadding(padding: Rect)

Return in padding the insets suggested by this Drawable for placing content inside the drawable's bounds.

open Boolean

Tells if this Drawable will be automatically mirrored when its layout direction is RTL right-to-left.

open Boolean


Requires API level 23 (Android 6.0, Marshmallow) Requires API level 23 (Android 6.0, Marshmallow)

open Unit

Specifies tint color for this drawable as a color state list.

Protected methods
open Boolean
onStateChange(stateSet: IntArray!)

Inherited functions

Public constructors

<init>

NinePatchDrawable(bitmap: Bitmap!, chunk: ByteArray!, padding: Rect!, srcName: String!)

Deprecated: Use #NinePatchDrawable(Resources, Bitmap, byte[], Rect, String) to ensure that the drawable has correctly set its target density.

Create drawable from raw nine-patch data, not dealing with density.

<init>

NinePatchDrawable(res: Resources!, bitmap: Bitmap!, chunk: ByteArray!, padding: Rect!, srcName: String!)

Create drawable from raw nine-patch data, setting initial target density based on the display metrics of the resources.

<init>

NinePatchDrawable(patch: NinePatch)

Deprecated: Use #NinePatchDrawable(Resources, NinePatch) to ensure that the drawable has correctly set its target density.

Create drawable from existing nine-patch, not dealing with density.

Parameters
patch NinePatch: This value must never be null.

<init>

NinePatchDrawable(res: Resources?, patch: NinePatch)

Create drawable from existing nine-patch, setting initial target density based on the display metrics of the resources.

Parameters
res Resources?: This value may be null.
patch Resources?: This value must never be null.

Public methods

canApplyTheme

added in API level 21
open fun canApplyTheme(): Boolean

Requires API level 21 (Android 5.0, Lollipop) Requires API level 21 (Android 5.0, Lollipop)

draw

open fun draw(canvas: Canvas): Unit

getAlpha

added in API level 19
open fun getAlpha(): Int

Gets the current alpha value for the drawable. 0 means fully transparent, 255 means fully opaque. This method is implemented by Drawable subclasses and the value returned is specific to how that class treats alpha. The default return value is 255 if the class does not override this method to return a value specific to its use of alpha.
Requires API level 19 (Android 4.4, KitKat) Requires API level 19 (Android 4.4, KitKat)

Return
Int: Value is between 0 and 255 inclusive

setAlpha

open fun setAlpha(alpha: Int): Unit

setAutoMirrored

added in API level 19
open fun setAutoMirrored(mirrored: Boolean): Unit

Set whether this Drawable is automatically mirrored when its layout direction is RTL (right-to left). See android.util.LayoutDirection.
Requires API level 19 (Android 4.4, KitKat) Requires API level 19 (Android 4.4, KitKat)

Parameters
mirrored Boolean: Set to true if the Drawable should be mirrored, false if not.

getOpacity

open fun getOpacity(): Int

setTintMode

added in API level 21
open fun setTintMode(tintMode: PorterDuff.Mode!): Unit

Specifies a tint blending mode for this 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 #setColorFilter(ColorFilter) or #setColorFilter(int, PorterDuff.Mode) overrides tint.


Requires API level 21 (Android 5.0, Lollipop)
Requires API level 21 (Android 5.0, Lollipop)
Parameters
tintMode PorterDuff.Mode!: This value may be null.

applyTheme

added in API level 21
open fun applyTheme(t: Resources.Theme): Unit

Applies the specified theme to this Drawable and its children.
Requires API level 21 (Android 5.0, Lollipop)
Requires API level 21 (Android 5.0, Lollipop)

Parameters
t Resources.Theme: This value must never be null.

inflate

added in API level 21
open fun inflate(r: Resources, parser: XmlPullParser, attrs: AttributeSet, theme: Resources.Theme?): Unit

Inflate this Drawable from an XML resource optionally styled by a theme. This can't be called more than once for each Drawable. Note that framework may have called this once to create the Drawable instance from XML resource.
Requires API level 21 (Android 5.0, Lollipop) Requires API level 21 (Android 5.0, Lollipop)

Parameters
r Resources: Resources used to resolve attribute values This value must never be null.
parser Resources: XML parser from which to inflate this Drawable This value must never be null.
attrs Resources: Base set of attribute values This value must never be null.
theme Resources: Theme to apply, may be null This value may be null.
Exceptions
XmlPullParserException
IOException

setDither

open fun setDither(dither: Boolean): Unit

setFilterBitmap

open fun setFilterBitmap(filter: Boolean): Unit

getIntrinsicWidth

open fun getIntrinsicWidth(): Int

getOutline

added in API level 21
open fun getOutline(outline: Outline): Unit

Called to get the drawable to populate the Outline that defines its drawing area.

This method is called by the default android.view.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.
Requires API level 21 (Android 5.0, Lollipop)
Requires API level 21 (Android 5.0, Lollipop)

Parameters
outline Outline: This value must never be null.

mutate

added in API level 3
open fun mutate(): Drawable

Make this drawable mutable. This operation cannot be reversed. A mutable drawable is guaranteed to not share its state with any other drawable. This is especially useful when you need to modify properties of drawables loaded from resources. By default, all drawables instances loaded from the same resource share a common state; if you modify the state of one instance, all the other instances will receive the same modification. Calling this method on a mutable Drawable will have no effect.
Requires API level 3 (Android 1.5, Cupcake) Requires API level 3 (Android 1.5, Cupcake)

Return
Drawable: This drawable. This value will never be null.

getIntrinsicHeight

open fun getIntrinsicHeight(): Int

isStateful

open fun isStateful(): Boolean

setTargetDensity

added in API level 4
open fun setTargetDensity(canvas: Canvas): Unit

Set the density scale at which this drawable will be rendered. This method assumes the drawable will be rendered at the same density as the specified canvas.
Requires API level 4 (Android 1.6, Donut)

Parameters
canvas Canvas: The Canvas from which the density scale must be obtained. This value must never be null.

setTargetDensity

added in API level 4
open fun setTargetDensity(metrics: DisplayMetrics): Unit

Set the density scale at which this drawable will be rendered.
Requires API level 4 (Android 1.6, Donut)

Parameters
metrics DisplayMetrics: The DisplayMetrics indicating the density scale for this drawable. This value must never be null.

setTargetDensity

added in API level 4
open fun setTargetDensity(density: Int): Unit

Set the density at which this drawable will be rendered.
Requires API level 4 (Android 1.6, Donut)

Parameters
density Int: The density scale for this drawable.

getPaint

open fun getPaint(): Paint
Return
Paint: This value will never be null.

setColorFilter

open fun setColorFilter(colorFilter: ColorFilter?): Unit

Specify an optional color filter for the 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.

Parameters
colorFilter ColorFilter?: This value may be null.

getTransparentRegion

open fun getTransparentRegion(): Region?

getConstantState

open fun getConstantState(): Drawable.ConstantState?

getPadding

open fun getPadding(padding: Rect): Boolean

Return in padding the insets suggested by this Drawable for placing content inside the drawable's bounds. Positive values move toward the center of the Drawable (set Rect.inset).

Parameters
padding Rect: This value must never be null.
Return
Boolean: true if this drawable actually has a padding, else false. When false is returned, the padding is always set to 0.

isAutoMirrored

added in API level 19
open fun isAutoMirrored(): Boolean

Tells if this Drawable will be automatically mirrored when its layout direction is RTL right-to-left. See android.util.LayoutDirection.
Requires API level 19 (Android 4.4, KitKat) Requires API level 19 (Android 4.4, KitKat)

Return
Boolean: boolean Returns true if this Drawable will be automatically mirrored.

isFilterBitmap

added in API level 23
open fun isFilterBitmap(): Boolean


Requires API level 23 (Android 6.0, Marshmallow) Requires API level 23 (Android 6.0, Marshmallow)

Return
Boolean: whether this drawable filters its bitmaps

setTintList

added in API level 21
open fun setTintList(tint: ColorStateList?): Unit

Specifies tint color for this drawable as a color state list.

A Drawable's drawing content will be blended together with its tint before it is drawn to the screen. This functions similarly to #setColorFilter(int, PorterDuff.Mode).

Note: Setting a color filter via #setColorFilter(ColorFilter) or #setColorFilter(int, PorterDuff.Mode) overrides tint.


Requires API level 21 (Android 5.0, Lollipop)
Requires API level 21 (Android 5.0, Lollipop)
Parameters
tint ColorStateList?: This value may be null.

Protected methods

onStateChange

protected open fun onStateChange(stateSet: IntArray!): Boolean