Most visited

Recently visited

ResourcesCompat

public final class ResourcesCompat
extends Object

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


Helper for accessing features in Resources introduced after API level 4 in a backwards compatible fashion.

Summary

Public methods

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

Returns a themed color integer associated with a particular resource ID.

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

Returns a themed color state list associated with a particular resource ID.

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

Return a drawable object associated with a particular resource ID and styled for the specified theme.

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

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

Inherited methods

From class java.lang.Object

Public methods

getColor

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

Returns a themed color integer associated with a particular resource ID. If the resource holds a complex ColorStateList, then the default color from the set is returned.

Prior to API level 23, the theme will not be applied and this method calls through to 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)

Returns a themed color state list associated with a particular resource ID. The resource may contain either a single raw color value or a complex ColorStateList holding multiple possible colors.

Prior to API level 23, the theme will not be applied and this method calls through to 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)

Return a drawable object associated with a particular resource ID and styled for the specified theme. Various types of objects will be returned depending on the underlying resource -- for example, a solid color, PNG image, scalable image, etc.

Prior to API level 21, the theme will not be applied and this method simply calls through to 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)

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

Prior to API level 15, the theme and density will not be applied and this method simply calls through to getDrawable(int).

Prior to API level 21, the theme will not be applied and this method calls through to 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!