Resources.GetDrawable Method
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.
Overloads
GetDrawable(Int32) |
Return a drawable object associated with a particular resource ID. |
GetDrawable(Int32, Resources+Theme) |
Return a drawable object associated with a particular resource ID. |
GetDrawable(Int32)
Return a drawable object associated with a particular resource ID.
[Android.Runtime.Register("getDrawable", "(I)Landroid/graphics/drawable/Drawable;", "GetGetDrawable_IHandler")]
public virtual Android.Graphics.Drawables.Drawable? GetDrawable (int id);
[<Android.Runtime.Register("getDrawable", "(I)Landroid/graphics/drawable/Drawable;", "GetGetDrawable_IHandler")>]
abstract member GetDrawable : int -> Android.Graphics.Drawables.Drawable
override this.GetDrawable : int -> Android.Graphics.Drawables.Drawable
Parameters
- id
- Int32
The desired resource identifier, as generated by the aapt tool. This integer encodes the package, type, and resource entry. The value 0 is an invalid identifier.
Returns
Drawable An object that can be used to draw this resource.
- Attributes
Exceptions
Throws NotFoundException if the given ID does not exist.
Remarks
Return a drawable object associated with a particular resource ID. Various types of objects will be returned depending on the underlying resource -- for example, a solid color, PNG image, scalable image, etc. The Drawable API hides these implementation details.
<p class="note"><strong>Note:</strong> Prior to android.os.Build.VERSION_CODES#JELLY_BEAN
, this function would not correctly retrieve the final configuration density when the resource ID passed here is an alias to another Drawable resource. This means that if the density configuration of the alias resource is different than the actual resource, the density of the returned Drawable would be incorrect, resulting in bad scaling. To work around this, you can instead manually resolve the aliased reference by using #getValue(int, TypedValue, boolean)
and passing true
for resolveRefs
. The resulting TypedValue#resourceId
value may be passed to this method.</p>
<p class="note"><strong>Note:</strong> To obtain a themed drawable, use android.content.Context#getDrawable(int) Context.getDrawable(int)
or #getDrawable(int, Theme)
passing the desired theme.</p>
This member is deprecated. Use #getDrawable(int, Theme)
instead.
Java documentation for android.content.res.Resources.getDrawable(int)
.
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.
See also
- <xref:Android.Content.Res.Resources.GetDrawable(System.Int32%2c+.Theme)>
Applies to
GetDrawable(Int32, Resources+Theme)
Return a drawable object associated with a particular resource ID.
[Android.Runtime.Register("getDrawable", "(ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;", "GetGetDrawable_ILandroid_content_res_Resources_Theme_Handler")]
public virtual Android.Graphics.Drawables.Drawable? GetDrawable (int id, Android.Content.Res.Resources.Theme? theme);
[<Android.Runtime.Register("getDrawable", "(ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;", "GetGetDrawable_ILandroid_content_res_Resources_Theme_Handler")>]
abstract member GetDrawable : int * Android.Content.Res.Resources.Theme -> Android.Graphics.Drawables.Drawable
override this.GetDrawable : int * Android.Content.Res.Resources.Theme -> Android.Graphics.Drawables.Drawable
Parameters
- id
- Int32
The desired resource identifier, as generated by the aapt tool. This integer encodes the package, type, and resource entry. The value 0 is an invalid identifier.
- theme
- Resources.Theme
The theme used to style the drawable attributes, may be null
.
Returns
Drawable An object that can be used to draw this resource.
- Attributes
Exceptions
Throws NotFoundException if the given ID does not exist.
Remarks
Java documentation for android.content.res.Resources.getDrawable(int)
.
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.