Drawable Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
A Drawable is a general abstraction for "something that can be drawn.
[Android.Runtime.Register("android/graphics/drawable/Drawable", DoNotGenerateAcw=true)]
public abstract class Drawable : Java.Lang.Object
[<Android.Runtime.Register("android/graphics/drawable/Drawable", DoNotGenerateAcw=true)>]
type Drawable = class
inherit Object
- Inheritance
- Derived
- Attributes
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 android.view.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:
<ul> <li> The #setBounds
method <var>must</var> 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 #getIntrinsicHeight
and #getIntrinsicWidth
methods.
<li> The #getPadding
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.
<li> The #setState
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.
<li> The #setLevel
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.
<li> A Drawable can perform animations by calling back to its client through the Callback
interface. All clients should support this interface (via #setCallback
) so that animations will work. A simple way to do this is through the system facilities such as android.view.View#setBackground(Drawable)
and android.widget.ImageView
. </ul>
Though usually not visible to the application, Drawables may take a variety of forms:
<ul> <li> <b>Bitmap</b>: the simplest Drawable, a PNG or JPEG image. <li> <b>Nine Patch</b>: an extension to the PNG format allows it to specify information about how to stretch it and place things inside of it. <li><b>Vector</b>: a drawable defined in an XML file as a set of points, lines, and curves along with its associated color information. This type of drawable can be scaled without loss of display quality. <li> <b>Shape</b>: contains simple drawing commands instead of a raw bitmap, allowing it to resize better in some cases. <li> <b>Layers</b>: a compound drawable, which draws multiple underlying drawables on top of each other. <li> <b>States</b>: a compound drawable that selects one of a set of drawables based on its state. <li> <b>Levels</b>: a compound drawable that selects one of a set of drawables based on its level. <li> <b>Scale</b>: a compound drawable with a single child drawable, whose overall size is modified based on the current level. </ul>
"Custom"><h3>Custom drawables</h3>
All versions of Android allow the Drawable class to be extended and used at run time in place of framework-provided drawable classes. Starting in android.os.Build.VERSION_CODES#N API 24
, custom drawables classes may also be used in XML.
<strong>Note:</strong> Custom drawable classes are only accessible from within your application package. Other applications will not be able to load them.
At a minimum, custom drawable classes must implement the abstract methods on Drawable and should override the Drawable#draw(Canvas)
method to draw content.
Custom drawables classes may be used in XML in multiple ways: <ul> <li> Using the fully-qualified class name as the XML element name. For this method, the custom drawable class must be a public top-level class.
<com.myapp.MyCustomDrawable xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#ffff0000" />
</li> <li> Using <em>drawable</em> as the XML element name and specifying the fully-qualified class name from the <em>class</em> attribute. This method may be used for both public top-level classes and public static inner classes.
<drawable xmlns:android="http://schemas.android.com/apk/res/android"
class="com.myapp.MyTopLevelClass$InnerCustomDrawable"
android:color="#ffff0000" />
</li> </ul>
<div class="special reference"> <h3>Developer Guides</h3>
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.
</div>
Java documentation for android.graphics.drawable.Drawable
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Constructors
Drawable() | |
Drawable(IntPtr, JniHandleOwnership) |
A constructor used when creating managed representations of JNI objects; called by the runtime. |
Properties
Alpha |
Gets the current alpha value for the drawable. |
AutoMirrored |
Tells if this Drawable will be automatically mirrored when its layout direction is RTL right-to-left. -or- Set whether this Drawable is automatically mirrored when its layout direction is RTL (right-to left). |
Bounds |
Return the drawable's bounds Rect. -or- Specify a bounding rectangle for the Drawable. |
Callback |
Return the current |
ChangingConfigurations |
Return a mask of the configuration parameters for which this drawable may change, requiring that it be re-created. -or- Set a mask of the configuration parameters for which this drawable may change, requiring that it be re-created. |
Class |
Returns the runtime class of this |
ColorFilter |
Returns the current color filter, or |
Current | |
DirtyBounds |
Return the drawable's dirty bounds Rect. |
Handle |
The handle to the underlying Android instance. (Inherited from Object) |
HasFocusStateSpecified |
Indicates whether this drawable has at least one state spec explicitly
specifying |
IntrinsicHeight |
Returns the drawable's intrinsic height. |
IntrinsicWidth |
Returns the drawable's intrinsic width. |
IsFilterBitmap | |
IsProjected |
Whether this drawable requests projection. |
IsStateful |
Indicates whether this drawable will change its appearance based on state. |
IsVisible | |
JniIdentityHashCode | (Inherited from Object) |
JniPeerMembers | |
LayoutDirection |
Returns the resolved layout direction for this Drawable. |
Level |
Retrieve the current level. |
MinimumHeight |
Returns the minimum height suggested by this Drawable. |
MinimumWidth |
Returns the minimum width suggested by this Drawable. |
Opacity |
Return the opacity/transparency of this Drawable. |
OpticalInsets |
Return in insets the layout insets suggested by this Drawable for use with alignment operations during layout. |
PeerReference | (Inherited from Object) |
ThresholdClass |
This API supports the Mono for Android infrastructure and is not intended to be used directly from your code. |
ThresholdType |
This API supports the Mono for Android infrastructure and is not intended to be used directly from your code. |
TransparentRegion |
Returns a Region representing the part of the Drawable that is completely transparent. |
Methods
ApplyTheme(Resources+Theme) |
Applies the specified theme to this Drawable and its children. |
CanApplyTheme() | |
ClearColorFilter() |
Removes the color filter for this drawable. |
Clone() |
Creates and returns a copy of this object. (Inherited from Object) |
CopyBounds() |
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). |
CreateFromPath(String) |
Create a drawable from file path name. |
CreateFromPathAsync(String) | |
CreateFromResourceStream(Resources, TypedValue, Stream, String, BitmapFactory+Options) |
Create a drawable from an inputstream, using the given resources and value to determine density information. |
CreateFromResourceStream(Resources, TypedValue, Stream, String) |
Create a drawable from an inputstream, using the given resources and value to determine density information. |
CreateFromResourceStreamAsync(Resources, TypedValue, Stream, String, BitmapFactory+Options) | |
CreateFromResourceStreamAsync(Resources, TypedValue, Stream, String) | |
CreateFromStream(Stream, String) |
Create a drawable from an inputstream |
CreateFromStreamAsync(Stream, String) | |
CreateFromXml(Resources, XmlReader, Resources+Theme) |
Create a drawable from an XML document. |
CreateFromXml(Resources, XmlReader) |
Create a drawable from an XML document. |
CreateFromXmlAsync(Resources, XmlReader, Resources+Theme) | |
CreateFromXmlAsync(Resources, XmlReader) | |
CreateFromXmlInner(Resources, XmlReader, IAttributeSet, Resources+Theme) |
Create from inside an XML document. |
CreateFromXmlInner(Resources, XmlReader, IAttributeSet) |
Create from inside an XML document. |
Dispose() | (Inherited from Object) |
Dispose(Boolean) | (Inherited from Object) |
Draw(Canvas) |
Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha) and color filter (set via setColorFilter). |
Equals(Object) |
Indicates whether some other object is "equal to" this one. (Inherited from Object) |
GetConstantState() |
Return a |
GetHashCode() |
Returns a hash code value for the object. (Inherited from Object) |
GetHotspotBounds(Rect) |
Populates |
GetOutline(Outline) |
Called to get the drawable to populate the Outline that defines its drawing area. |
GetPadding(Rect) |
Return in padding the insets suggested by this Drawable for placing content inside the drawable's bounds. |
GetState() |
Describes the current state, as a union of primitve states, such as
|
Inflate(Resources, XmlReader, IAttributeSet, Resources+Theme) |
Inflate this Drawable from an XML resource. |
Inflate(Resources, XmlReader, IAttributeSet) |
Inflate this Drawable from an XML resource. |
InflateAsync(Resources, XmlReader, IAttributeSet, Resources+Theme) | |
InflateAsync(Resources, XmlReader, IAttributeSet) | |
InvalidateSelf() |
Use the current |
JavaFinalize() |
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. (Inherited from Object) |
JumpToCurrentState() |
If this Drawable does transition animations between states, ask that it immediately jump to the current state and skip any active animations. |
Mutate() |
Make this drawable mutable. |
Notify() |
Wakes up a single thread that is waiting on this object's monitor. (Inherited from Object) |
NotifyAll() |
Wakes up all threads that are waiting on this object's monitor. (Inherited from Object) |
OnBoundsChange(Rect) |
Override this in your subclass to change appearance if you vary based on the bounds. |
OnLayoutDirectionChanged(Int32) |
Called when the drawable's resolved layout direction changes. |
OnLevelChange(Int32) |
Override this in your subclass to change appearance if you vary based on level. |
OnStateChange(Int32[]) |
Override this in your subclass to change appearance if you recognize the specified state. |
ResolveOpacity(Int32, Int32) |
Return the appropriate opacity value for two source opacities. |
ScheduleSelf(Action, Int64) | |
ScheduleSelf(IRunnable, Int64) |
Use the current |
SetAlpha(Int32) |
Specify an alpha value for the drawable. |
SetBounds(Int32, Int32, Int32, Int32) |
Specify a bounding rectangle for the Drawable. |
SetCallback(Drawable+ICallback) |
Bind a |
SetColorFilter(Color, PorterDuff+Mode) |
Specify a color and Porter-Duff mode to be the color filter for this drawable. |
SetColorFilter(ColorFilter) |
Specify an optional color filter for the 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. |
SetHandle(IntPtr, JniHandleOwnership) |
Sets the Handle property. (Inherited from Object) |
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. |
SetLayoutDirection(LayoutDirection) |
Set the layout direction for this drawable. |
SetLevel(Int32) |
Specify the level for the drawable. |
SetState(Int32[]) |
Specify a set of states for the drawable. |
SetTint(Int32) |
Specifies tint color for this drawable. |
SetTintBlendMode(BlendMode) |
Specifies a tint blending mode 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) |
Set whether this Drawable is visible. |
ToArray<T>() | (Inherited from Object) |
ToString() |
Returns a string representation of the object. (Inherited from Object) |
UnregisterFromRuntime() | (Inherited from Object) |
UnscheduleSelf(Action) | |
UnscheduleSelf(IRunnable) |
Use the current |
Wait() |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>. (Inherited from Object) |
Wait(Int64, Int32) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Wait(Int64) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Explicit Interface Implementations
IJavaPeerable.Disposed() | (Inherited from Object) |
IJavaPeerable.DisposeUnlessReferenced() | (Inherited from Object) |
IJavaPeerable.Finalized() | (Inherited from Object) |
IJavaPeerable.JniManagedPeerState | (Inherited from Object) |
IJavaPeerable.SetJniIdentityHashCode(Int32) | (Inherited from Object) |
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) | (Inherited from Object) |
IJavaPeerable.SetPeerReference(JniObjectReference) | (Inherited from Object) |
Extension Methods
JavaCast<TResult>(IJavaObject) |
Performs an Android runtime-checked type conversion. |
JavaCast<TResult>(IJavaObject) | |
GetJniTypeName(IJavaPeerable) |