# ResourcesCompat

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  
belongs to Maven artifact com.android.support:support-compat:28.0.0-alpha1  
Summary:[Nested Classes](https://developer.android.com/reference/android/support/v4/content/res/ResourcesCompat#nestedclasses)\|[Methods](https://developer.android.com/reference/android/support/v4/content/res/ResourcesCompat#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/v4/content/res/ResourcesCompat#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/v4/content/res/ResourcesCompat#)  

# ResourcesCompat

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public

final

class
ResourcesCompat
`  
`

extends Object


``


`

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

<br />

*** ** * ** ***

Helper for accessing features in[Resources](https://developer.android.com/reference/android/content/res/Resources.html).

## Summary

|                                                                                             ### Nested classes                                                                                             ||
|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` class` | [ResourcesCompat.FontCallback](https://developer.android.com/reference/android/support/v4/content/res/ResourcesCompat.FontCallback) Interface used to receive asynchronous font fetching events. |

|                                                                                                                                                                                                                                                                                                                                                                            ### Public methods                                                                                                                                                                                                                                                                                                                                                                             ||
|-------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` static int`                                                                                               | ` `[getColor](https://developer.android.com/reference/android/support/v4/content/res/ResourcesCompat#getColor(android.content.res.Resources, int, android.content.res.Resources.Theme))`(`[Resources](https://developer.android.com/reference/android/content/res/Resources.html)` res, int id, `[Resources.Theme](https://developer.android.com/reference/android/content/res/Resources.Theme.html)` theme) ` Returns a themed color integer associated with a particular resource ID.                                                                                                                                                                      |
| ` static `[ColorStateList](https://developer.android.com/reference/android/content/res/ColorStateList.html) | ` `[getColorStateList](https://developer.android.com/reference/android/support/v4/content/res/ResourcesCompat#getColorStateList(android.content.res.Resources, int, android.content.res.Resources.Theme))`(`[Resources](https://developer.android.com/reference/android/content/res/Resources.html)` res, int id, `[Resources.Theme](https://developer.android.com/reference/android/content/res/Resources.Theme.html)` theme) ` Returns a themed color state list associated with a particular resource ID.                                                                                                                                                 |
| ` static `[Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable.html)       | ` `[getDrawable](https://developer.android.com/reference/android/support/v4/content/res/ResourcesCompat#getDrawable(android.content.res.Resources, int, android.content.res.Resources.Theme))`(`[Resources](https://developer.android.com/reference/android/content/res/Resources.html)` res, int id, `[Resources.Theme](https://developer.android.com/reference/android/content/res/Resources.Theme.html)` theme) ` Return a drawable object associated with a particular resource ID and styled for the specified theme.                                                                                                                                   |
| ` static `[Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable.html)       | ` `[getDrawableForDensity](https://developer.android.com/reference/android/support/v4/content/res/ResourcesCompat#getDrawableForDensity(android.content.res.Resources, int, int, android.content.res.Resources.Theme))`(`[Resources](https://developer.android.com/reference/android/content/res/Resources.html)` res, int id, int density, `[Resources.Theme](https://developer.android.com/reference/android/content/res/Resources.Theme.html)` theme) ` Return a drawable object associated with a particular resource ID for the given screen density in DPI and styled for the specified theme.                                                         |
| ` static `[Typeface](https://developer.android.com/reference/android/graphics/Typeface.html)                | ` `[getFont](https://developer.android.com/reference/android/support/v4/content/res/ResourcesCompat#getFont(android.content.Context, int))`(`[Context](https://developer.android.com/reference/android/content/Context.html)` context, int id) ` Returns a font Typeface associated with a particular resource ID.                                                                                                                                                                                                                                                                                                                                           |
| ` static void`                                                                                              | ` `[getFont](https://developer.android.com/reference/android/support/v4/content/res/ResourcesCompat#getFont(android.content.Context, int, android.support.v4.content.res.ResourcesCompat.FontCallback, android.os.Handler))`(`[Context](https://developer.android.com/reference/android/content/Context.html)` context, int id, `[ResourcesCompat.FontCallback](https://developer.android.com/reference/android/support/v4/content/res/ResourcesCompat.FontCallback)` fontCallback, `[Handler](https://developer.android.com/reference/android/os/Handler.html)` handler) ` Returns a font Typeface associated with a particular resource ID asynchronously. |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v4/content/res/ResourcesCompat#)From class` java.lang.Object ` |-------------------|-------------------------------| | ` Object`         | ` clone() `                   | | ` boolean`        | ` equals(Object arg0) `       | | ` void`           | ` finalize() `                | | ` final Class<?>` | ` getClass() `                | | ` int`            | ` hashCode() `                | | ` final void`     | ` notify() `                  | | ` final void`     | ` notifyAll() `               | | ` String`         | ` toString() `                | | ` final void`     | ` wait(long arg0, int arg1) ` | | ` final void`     | ` wait(long arg0) `           | | ` final void`     | ` wait() `                    | ||

## Public methods

### getColor

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
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](https://developer.android.com/reference/android/content/res/ColorStateList.html), 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)](https://developer.android.com/reference/android/content/res/Resources.html#getColor(int)).

<br />

|                                                                                        Parameters                                                                                        ||
|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `res`   | `Resources` <br />                                                                                                                                                              |
| `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. <br /> |
| `theme` | `Resources.Theme`: The theme used to style the color attributes, may be`null`. <br />                                                                                           |

|                           Returns                           ||
|-------|------------------------------------------------------|
| `int` | A single color value in the form`0xAARRGGBB`. <br /> |

|                                                                                        Throws                                                                                         ||
|-----------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------|
| [Resources.NotFoundException](https://developer.android.com/reference/android/content/res/Resources.NotFoundException.html) | Throws NotFoundException if the given ID does not exist. |

### getColorStateList

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
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](https://developer.android.com/reference/android/content/res/ColorStateList.html)holding multiple possible colors.

Prior to API level 23, the theme will not be applied and this method calls through to[getColorStateList(int)](https://developer.android.com/reference/android/content/res/Resources.html#getColorStateList(int)).

<br />

|                                                                                                                                           Parameters                                                                                                                                           ||
|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `res`   | `Resources` <br />                                                                                                                                                                                                                                                                    |
| `id`    | `int`: The desired resource identifier of a[ColorStateList](https://developer.android.com/reference/android/content/res/ColorStateList.html), as generated by the aapt tool. This integer encodes the package, type, and resource entry. The value 0 is an invalid identifier. <br /> |
| `theme` | `Resources.Theme`: The theme used to style the color attributes, may be`null`. <br />                                                                                                                                                                                                 |

|                                                                                                                  Returns                                                                                                                  ||
|---------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|
| [ColorStateList](https://developer.android.com/reference/android/content/res/ColorStateList.html) | A themed ColorStateList object containing either a single solid color or multiple colors that can be selected based on a state. <br /> |

|                                                                                        Throws                                                                                         ||
|-----------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------|
| [Resources.NotFoundException](https://developer.android.com/reference/android/content/res/Resources.NotFoundException.html) | Throws NotFoundException if the given ID does not exist. |

### getDrawable

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
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)](https://developer.android.com/reference/android/content/res/Resources.html#getDrawable(int)).

<br />

|                                                                                        Parameters                                                                                        ||
|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `res`   | `Resources` <br />                                                                                                                                                              |
| `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. <br /> |
| `theme` | `Resources.Theme`: The theme used to style the drawable attributes, may be`null`. <br />                                                                                        |

|                                                                            Returns                                                                             ||
|---------------------------------------------------------------------------------------------|-------------------------------------------------------------------|
| [Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable.html) | Drawable An object that can be used to draw this resource. <br /> |

|                                                                                        Throws                                                                                         ||
|-----------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------|
| [Resources.NotFoundException](https://developer.android.com/reference/android/content/res/Resources.NotFoundException.html) | Throws NotFoundException if the given ID does not exist. |

### getDrawableForDensity

added in[version 24.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
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)](https://developer.android.com/reference/android/content/res/Resources.html#getDrawable(int)).

Prior to API level 21, the theme will not be applied and this method calls through to Resources#getDrawableForDensity(int, int).

<br />

|                                                                                         Parameters                                                                                         ||
|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `res`     | `Resources` <br />                                                                                                                                                              |
| `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. <br /> |
| `density` | `int`: The desired screen density indicated by the resource as found in[DisplayMetrics](https://developer.android.com/reference/android/util/DisplayMetrics.html). <br />       |
| `theme`   | `Resources.Theme`: The theme used to style the drawable attributes, may be`null`. <br />                                                                                        |

|                                                                            Returns                                                                             ||
|---------------------------------------------------------------------------------------------|-------------------------------------------------------------------|
| [Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable.html) | Drawable An object that can be used to draw this resource. <br /> |

|                                                                                        Throws                                                                                         ||
|-----------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------|
| [Resources.NotFoundException](https://developer.android.com/reference/android/content/res/Resources.NotFoundException.html) | Throws NotFoundException if the given ID does not exist. |

### getFont

added in[version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
Typeface getFont (Context context, 
                int id)
```

Returns a font Typeface associated with a particular resource ID.

This method will block the calling thread to retrieve the requested font, including if it is from a font provider. If you wish to not have this behavior, use[getFont(Context, int, FontCallback, Handler)](https://developer.android.com/reference/android/support/v4/content/res/ResourcesCompat#getFont(android.content.Context, int, android.support.v4.content.res.ResourcesCompat.FontCallback, android.os.Handler))instead.

Prior to API level 23, font resources with more than one font in a family will only load the font closest to a regular weight typeface.

<br />

|                                                                                                                                    Parameters                                                                                                                                     ||
|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context` | `Context`: A context to retrieve the Resources from. <br />                                                                                                                                                                                                            |
| `id`      | `int`: The desired resource identifier of a[Typeface](https://developer.android.com/reference/android/graphics/Typeface.html), as generated by the aapt tool. This integer encodes the package, type, and resource entry. The value 0 is an invalid identifier. <br /> |

|                                                      Returns                                                       ||
|------------------------------------------------------------------------------------|--------------------------------|
| [Typeface](https://developer.android.com/reference/android/graphics/Typeface.html) | A font Typeface object. <br /> |

|                                                                                        Throws                                                                                         ||
|-----------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------|
| [Resources.NotFoundException](https://developer.android.com/reference/android/content/res/Resources.NotFoundException.html) | Throws NotFoundException if the given ID does not exist. |

**See also:**

- [getFont(Context, int, FontCallback, Handler)](https://developer.android.com/reference/android/support/v4/content/res/ResourcesCompat#getFont(android.content.Context, int, android.support.v4.content.res.ResourcesCompat.FontCallback, android.os.Handler))  

### getFont

added in[version 27.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void getFont (Context context, 
                int id, 
                ResourcesCompat.FontCallback fontCallback, 
                Handler handler)
```

Returns a font Typeface associated with a particular resource ID asynchronously.

Prior to API level 23, font resources with more than one font in a family will only load the font closest to a regular weight typeface.

<br />

<br />

|                                                                                                                                       Parameters                                                                                                                                       ||
|----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context`      | `Context`: A context to retrieve the Resources from. <br />                                                                                                                                                                                                            |
| `id`           | `int`: The desired resource identifier of a[Typeface](https://developer.android.com/reference/android/graphics/Typeface.html), as generated by the aapt tool. This integer encodes the package, type, and resource entry. The value 0 is an invalid identifier. <br /> |
| `fontCallback` | `ResourcesCompat.FontCallback`: A callback to receive async fetching of this font. The callback will be triggered on the UI thread. <br />                                                                                                                             |
| `handler`      | `Handler`: A handler for the thread the callback should be called on. If null, the callback will be called on the UI thread. <br />                                                                                                                                    |

|                                                                                        Throws                                                                                         ||
|-----------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------|
| [Resources.NotFoundException](https://developer.android.com/reference/android/content/res/Resources.NotFoundException.html) | Throws NotFoundException if the given ID does not exist. |

-

  ## Classes

  - [ConfigurationHelper](https://developer.android.com/reference/android/support/v4/content/res/ConfigurationHelper)
  - [ResourcesCompat](https://developer.android.com/reference/android/support/v4/content/res/ResourcesCompat)
  - [ResourcesCompat.FontCallback](https://developer.android.com/reference/android/support/v4/content/res/ResourcesCompat.FontCallback)