Android Guides | Samples

Android.Graphics.Drawables.Drawable Class

A Drawable is a general abstraction for "something that can be drawn.

See Also: Drawable

Syntax

[Android.Runtime.Register("android/graphics/drawable/Drawable", DoNotGenerateAcw=true)]
public abstract class Drawable : Object

Remarks

A Drawable is a general abstraction for "something that can be drawn." Most often you will deal with Drawable as the type of resource retrieved for drawing things to the screen; the Drawable class provides a generic API for dealing with an underlying visual resource that may take a variety of forms. Unlike a View, a Drawable does not have any facility to receive events or otherwise interact with the user.

In addition to simple drawing, Drawable provides a number of generic mechanisms for its client to interact with what is being drawn:

  • The Drawable.Bounds method must be called to tell the Drawable where it is drawn and how large it should be. All Drawables should respect the requested size, often simply by scaling their imagery. A client can find the preferred size for some Drawables with the Drawable.IntrinsicHeight and Drawable.IntrinsicWidth methods.
  • The Drawable.GetPadding(Rect) method can return from some Drawables information about how to frame content that is placed inside of them. For example, a Drawable that is intended to be the frame for a button widget would need to return padding that correctly places the label inside of itself.
  • The Drawable.SetState(Int32[]) method allows the client to tell the Drawable in which state it is to be drawn, such as "focused", "selected", etc. Some drawables may modify their imagery based on the selected state.
  • The Drawable.SetLevel(Int32) method allows the client to supply a single continuous controller that can modify the Drawable is displayed, such as a battery level or progress level. Some drawables may modify their imagery based on the current level.
  • A Drawable can perform animations by calling back to its client through the ICallback interface. All clients should support this interface (via Drawable.SetCallback(.ICallback)) so that animations will work. A simple way to do this is through the system facilities such as View.Background and ImageView.
Though usually not visible to the application, Drawables may take a variety of forms:
  • Bitmap: the simplest Drawable, a PNG or JPEG image.
  • Nine Patch: an extension to the PNG format allows it to specify information about how to stretch it and place things inside of it.
  • Shape: contains simple drawing commands instead of a raw bitmap, allowing it to resize better in some cases.
  • Layers: a compound drawable, which draws multiple underlying drawables on top of each other.
  • States: a compound drawable that selects one of a set of drawables based on its state.
  • Levels: a compound drawable that selects one of a set of drawables based on its level.
  • Scale: a compound drawable with a single child drawable, whose overall size is modified based on the current level.

Developer Guides

For more information about how to use drawables, read the Canvas and Drawables developer guide. For information and examples of creating drawable resources (XML or bitmap files that can be loaded in code), read the Drawable Resources document.

[Android Documentation]

Requirements

Namespace: Android.Graphics.Drawables
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1

The members of Android.Graphics.Drawables.Drawable are listed below.

See Also: Object

Public Constructors

Protected Constructors

A constructor used when creating managed representations of JNI objects; called by the runtime.

Public Properties

AlphaInt32. Gets the current alpha value for the drawable. 0 means fully transparent, 255 means fully opaque.
AutoMirroredBoolean. Tells if this Drawable will be automatically mirrored when its layout direction is RTL right-to-left.
BoundsRect. Return the drawable's bounds Rect.
CallbackDrawable+ICallback. Return the current ICallback implementation attached to this Drawable.
ChangingConfigurationsConfigChanges. Return a mask of the configuration parameters for which this drawable may change, requiring that it be re-created.
[read-only]
ColorFilterColorFilter. Returns the current color filter, or null if none set.
[read-only]
CurrentDrawable.
[read-only]
DirtyBoundsRect. Return the drawable's dirty bounds Rect.
[read-only]
IntrinsicHeightInt32. Return the intrinsic height of the underlying drawable object.
[read-only]
IntrinsicWidthInt32. Return the intrinsic width of the underlying drawable object.
[read-only]
IsStatefulBoolean. Indicates whether this drawable will change its appearance based on state.
[read-only]
IsVisibleBoolean.
[read-only]
LevelInt32. Retrieve the current level.
[read-only]
MinimumHeightInt32. Returns the minimum height suggested by this Drawable.
[read-only]
MinimumWidthInt32. Returns the minimum width suggested by this Drawable.
[read-only]
abstract
OpacityInt32. Return the opacity/transparency of this Drawable.
[read-only]
TransparentRegionRegion. Returns a Region representing the part of the Drawable that is completely transparent.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

ApplyTheme(Resources+Theme)
Applies the specified theme to this Drawable and its children.
CanApplyTheme() : Boolean
ClearColorFilter()
Removes the color filter for this drawable.
CopyBounds() : Rect
Return a copy of the drawable's bounds in a new Rect.
CopyBounds(Rect)
Return a copy of the drawable's bounds in the specified Rect (allocated by the caller).
static
CreateFromPath(String) : Drawable
Create a drawable from file path name.
static
CreateFromPathAsync(String) : System.Threading.Tasks.Task<Android.Graphics.Drawables.Drawable>
static
CreateFromResourceStream(Resources, TypedValue, Stream, String) : Drawable
Create a drawable from an inputstream, using the given resources and value to determine density information.
static
CreateFromResourceStream(Resources, TypedValue, Stream, String, BitmapFactory+Options) : Drawable
Create a drawable from an inputstream, using the given resources and value to determine density information.
static
CreateFromResourceStreamAsync(Resources, TypedValue, Stream, String) : System.Threading.Tasks.Task<Android.Graphics.Drawables.Drawable>
static
CreateFromResourceStreamAsync(Resources, TypedValue, Stream, String, BitmapFactory+Options) : System.Threading.Tasks.Task<Android.Graphics.Drawables.Drawable>
static
CreateFromStream(Stream, String) : Drawable
Create a drawable from an inputstream
static
CreateFromStreamAsync(Stream, String) : System.Threading.Tasks.Task<Android.Graphics.Drawables.Drawable>
static
CreateFromXml(Resources, XmlReader) : Drawable
Create a drawable from an XML document.
static
CreateFromXml(Resources, XmlReader, Resources+Theme) : Drawable
Create a drawable from an XML document using an optional NoType:android/content/res/Resources$Theme;Href=../../../../reference/android/content/res/Resources.Theme.html.
static
CreateFromXmlAsync(Resources, XmlReader) : System.Threading.Tasks.Task<Android.Graphics.Drawables.Drawable>
static
CreateFromXmlAsync(Resources, XmlReader, Resources+Theme) : System.Threading.Tasks.Task<Android.Graphics.Drawables.Drawable>
static
CreateFromXmlInner(Resources, XmlReader, IAttributeSet) : Drawable
Create from inside an XML document.
static
CreateFromXmlInner(Resources, XmlReader, IAttributeSet, Resources+Theme) : Drawable
Create a drawable from inside an XML document using an optional NoType:android/content/res/Resources$Theme;Href=../../../../reference/android/content/res/Resources.Theme.html.
abstract
Draw(Canvas)
Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha) and color filter (set via setColorFilter).
GetConstantState() : Drawable+ConstantState
Return a NoType:android/graphics/drawable/Drawable$ConstantState;Href=../../../../reference/android/graphics/drawable/Drawable.ConstantState.html instance that holds the shared state of this Drawable.
GetOutline(Outline)
Called to get the drawable to populate the Outline that defines its drawing area.
GetPadding(Rect) : Boolean
Return in padding the insets suggested by this Drawable for placing content inside the drawable's bounds.
GetState() : Int32[]
Describes the current state, as a union of primitve states, such as NoType:android/R$attr;Href=../../../../reference/android/R.attr.html#state_focused, NoType:android/R$attr;Href=../../../../reference/android/R.attr.html#state_selected, etc.
Inflate(Resources, XmlReader, IAttributeSet)
Inflate this Drawable from an XML resource.
Inflate(Resources, XmlReader, IAttributeSet, Resources+Theme)
Inflate this Drawable from an XML resource optionally styled by a theme.
InflateAsync(Resources, XmlReader, IAttributeSet) : Task
InflateAsync(Resources, XmlReader, IAttributeSet, Resources+Theme) : Task
InvalidateSelf()
Use the current ICallback implementation to have this Drawable redrawn.
JumpToCurrentState()
If this Drawable does transition animations between states, ask that it immediately jump to the current state and skip any active animations.
Mutate() : Drawable
Make this drawable mutable.
static
ResolveOpacity(Int32, Int32) : Int32
Return the appropriate opacity value for two source opacities.
ScheduleSelf(IRunnable, Int64)
Use the current ICallback implementation to have this Drawable scheduled.
ScheduleSelf(Action, Int64)
abstract
SetAlpha(Int32)
Specify an alpha value for the drawable. 0 means fully transparent, and 255 means fully opaque.
SetBounds(Int32, Int32, Int32, Int32)
Specify a bounding rectangle for the Drawable.
SetCallback(Drawable+ICallback)
Bind a ICallback object to this Drawable.
abstract
SetColorFilter(ColorFilter)
Specify an optional color filter for the drawable.
SetColorFilter(Color, PorterDuff+Mode)
Specify a color and Porter-Duff mode to be the color filter for this drawable.
SetDither(Boolean)
Set to true to have the drawable dither its colors when drawn to a device with fewer than 8-bits per color component.
SetFilterBitmap(Boolean)
Set to true to have the drawable filter its bitmaps with bilinear sampling when they are scaled or rotated.
SetHotspot(Single, Single)
Specifies the hotspot's location within the drawable.
SetHotspotBounds(Int32, Int32, Int32, Int32)
Sets the bounds to which the hotspot is constrained, if they should be different from the drawable bounds.
SetLevel(Int32) : Boolean
Specify the level for the drawable.
SetState(Int32[]) : Boolean
Specify a set of states for the drawable.
SetTint(Int32)
Specifies tint color for this drawable.
SetTintList(ColorStateList)
Specifies tint color for this drawable as a color state list.
SetTintMode(PorterDuff+Mode)
Specifies a tint blending mode for this drawable.
SetVisible(Boolean, Boolean) : Boolean
Set whether this Drawable is visible.
UnscheduleSelf(IRunnable)
Use the current ICallback implementation to have this Drawable unscheduled.
UnscheduleSelf(Action)

Protected Methods

OnBoundsChange(Rect)
Override this in your subclass to change appearance if you vary based on the bounds.
OnLevelChange(Int32) : Boolean
Override this in your subclass to change appearance if you vary based on level.
OnStateChange(Int32[]) : Boolean
Override this in your subclass to change appearance if you recognize the specified state.