Most visited

Recently visited

ResourcesCompat

public final class ResourcesCompat
extends Object

java.lang.Object
   ↳ android.support.v4.content.res.ResourcesCompat


Helper用于访问API级别4之后以向后兼容的方式引入的 Resources功能。

Summary

Public methods

static int getColor(Resources res, int id, Resources.Theme theme)

返回与特定资源ID关联的主题颜色整数。

static ColorStateList getColorStateList(Resources res, int id, Resources.Theme theme)

返回与特定资源ID关联的主题颜色状态列表。

static Drawable getDrawable(Resources res, int id, Resources.Theme theme)

返回与特定资源ID关联的可绘制对象,并为指定的主题创建样式。

static Drawable getDrawableForDensity(Resources res, int id, int density, Resources.Theme theme)

返回与DPI中给定屏幕密度的特定资源ID关联的可绘制对象,并为指定的主题创建样式。

Inherited methods

From class java.lang.Object

Public methods

getColor

int getColor (Resources res, 
                int id, 
                Resources.Theme theme)

返回与特定资源ID关联的主题颜色整数。 如果资源包含复杂的ColorStateList ,则返回该集合中的默认颜色。

在API级别23之前,主题将不会被应用,并且此方法调用 getColor(int)

Parameters
res Resources
id int: 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 color attributes, may be null.
Returns
int A single color value in the form 0xAARRGGBB.
Throws
Resources.NotFoundException Throws NotFoundException if the given ID does not exist.

getColorStateList

ColorStateList getColorStateList (Resources res, 
                int id, 
                Resources.Theme theme)

返回与特定资源ID关联的主题颜色状态列表。 该资源可能包含一个原始颜色值或包含多种可能颜色的复杂ColorStateList

在API级别23之前,主题将不会被应用,并且此方法调用至 getColorStateList(int)

Parameters
res Resources
id int: The desired resource identifier of a ColorStateList, 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 color attributes, may be null.
Returns
ColorStateList A themed ColorStateList object containing either a single solid color or multiple colors that can be selected based on a state.
Throws
Resources.NotFoundException Throws NotFoundException if the given ID does not exist.

getDrawable

Drawable getDrawable (Resources res, 
                int id, 
                Resources.Theme theme)

返回与特定资源ID关联的可绘制对象,并为指定的主题创建样式。 根据底层资源返回各种类型的对象 - 例如,纯色,PNG图像,可缩放图像等。

在API级别21之前,该主题将不会被应用,并且该方法简单地调用至 getDrawable(int)

Parameters
res Resources
id int: 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 Drawable An object that can be used to draw this resource.
Throws
Resources.NotFoundException Throws NotFoundException if the given ID does not exist.

getDrawableForDensity

Drawable getDrawableForDensity (Resources res, 
                int id, 
                int density, 
                Resources.Theme theme)

返回与DPI中给定屏幕密度的特定资源ID关联的可绘制对象,并为指定的主题创建样式。

在API级别15之前,主题和密度将不会被应用,并且此方法只需调用 getDrawable(int)

在API级别21之前,主题将不会被应用,并且此方法将调用Resources#getDrawableForDensity(int,int)。

Parameters
res Resources
id int: 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 int: The desired screen density indicated by the resource as found in DisplayMetrics.
theme Resources.Theme: The theme used to style the drawable attributes, may be null.
Returns
Drawable Drawable An object that can be used to draw this resource.
Throws
Resources.NotFoundException Throws NotFoundException if the given ID does not exist.

Hooray!