public final class ResourcesCompat
extends Object
| java.lang.Object | |
| android.support.v4.content.res.ResourcesCompat | |
Helper用于访问API级别4之后以向后兼容的方式引入的 Resources功能。
公共方法(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) |
|
|---|---|
java.lang.Object
|
|
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. |
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. |
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. |
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. |