Freigeben über


Resources.GetDrawableForDensity Method

Definition

Overloads

GetDrawableForDensity(Int32, Int32)

Return a drawable object associated with a particular resource ID for the given screen density in DPI.

GetDrawableForDensity(Int32, Int32, Resources+Theme)

Return a drawable object associated with a particular resource ID for the given screen density in DPI.

GetDrawableForDensity(Int32, Int32)

Return a drawable object associated with a particular resource ID for the given screen density in DPI.

[Android.Runtime.Register("getDrawableForDensity", "(II)Landroid/graphics/drawable/Drawable;", "GetGetDrawableForDensity_IIHandler")]
public virtual Android.Graphics.Drawables.Drawable? GetDrawableForDensity (int id, int density);
[<Android.Runtime.Register("getDrawableForDensity", "(II)Landroid/graphics/drawable/Drawable;", "GetGetDrawableForDensity_IIHandler")>]
abstract member GetDrawableForDensity : int * int -> Android.Graphics.Drawables.Drawable
override this.GetDrawableForDensity : int * 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.

density
Int32

the desired screen density indicated by the resource as found in DisplayMetrics. A value of 0 means to use the density returned from #getConfiguration(). This is equivalent to calling #getDrawable(int).

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 for the given screen density in DPI. This will set the drawable's density to be the device's density multiplied by the ratio of actual drawable density to requested density. This allows the drawable to be scaled up to the correct size if needed. 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> To obtain a themed drawable, use android.content.Context#getDrawable(int) Context.getDrawable(int) or #getDrawableForDensity(int, int, Theme) passing the desired theme.</p>

This member is deprecated. Use #getDrawableForDensity(int, int, Theme) instead.

Java documentation for android.content.res.Resources.getDrawableForDensity(int, 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.GetDrawableForDensity(System.Int32%2c+System.Int32%2c+System.Int32)>

Applies to

GetDrawableForDensity(Int32, Int32, Resources+Theme)

Return a drawable object associated with a particular resource ID for the given screen density in DPI.

[Android.Runtime.Register("getDrawableForDensity", "(IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;", "GetGetDrawableForDensity_IILandroid_content_res_Resources_Theme_Handler")]
public virtual Android.Graphics.Drawables.Drawable? GetDrawableForDensity (int id, int density, Android.Content.Res.Resources.Theme? theme);
[<Android.Runtime.Register("getDrawableForDensity", "(IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;", "GetGetDrawableForDensity_IILandroid_content_res_Resources_Theme_Handler")>]
abstract member GetDrawableForDensity : int * int * Android.Content.Res.Resources.Theme -> Android.Graphics.Drawables.Drawable
override this.GetDrawableForDensity : int * 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.

density
Int32

the desired screen density indicated by the resource as found in DisplayMetrics. A value of 0 means to use the density returned from #getConfiguration(). This is equivalent to calling #getDrawable(int).

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.getDrawableForDensity(int, 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.

Applies to