# ResourcesCompat

# ResourcesCompat

Artifact:[androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core)  
[View Source](https://cs.android.com/search?q=file:androidx/core/content/res/ResourcesCompat.java+class:androidx.core.content.res.ResourcesCompat)  
Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/core/content/res/ResourcesCompat "View this page in Java")

<br />

```
class ResourcesCompat
```

<br />

*** ** * ** ***

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

## Summary

|                                                                                                                                        ### Nested types                                                                                                                                        |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `abstract class `[ResourcesCompat.FontCallback](https://developer.android.com/reference/kotlin/androidx/core/content/res/ResourcesCompat.FontCallback) Interface used to receive asynchronous font fetching events.                                                                            |
| `class `[ResourcesCompat.ThemeCompat](https://developer.android.com/reference/kotlin/androidx/core/content/res/ResourcesCompat.ThemeCompat) Provides backward-compatible implementations for new[Theme](https://developer.android.com/reference/android/content/res/Resources.Theme.html)APIs. |

|                                                                               ### Constants                                                                                |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------|
| `const @`[AnyRes](https://developer.android.com/reference/kotlin/androidx/annotation/AnyRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [ID_NULL](https://developer.android.com/reference/kotlin/androidx/core/content/res/ResourcesCompat#ID_NULL())` = 0` The`null`resource ID. |

|                                                                                 ### Public functions                                                                                 |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                          | [clearCachesForTheme](https://developer.android.com/reference/kotlin/androidx/core/content/res/ResourcesCompat#clearCachesForTheme(android.content.res.Resources.Theme))`(theme: `[Resources.Theme](https://developer.android.com/reference/android/content/res/Resources.Theme.html)`)` Clears cached values associated with the specified[Theme](https://developer.android.com/reference/android/content/res/Resources.Theme.html).                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `java-static `[Typeface](https://developer.android.com/reference/android/graphics/Typeface.html)`?`                                                                                  | [getCachedFont](https://developer.android.com/reference/kotlin/androidx/core/content/res/ResourcesCompat#getCachedFont(android.content.Context,int))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`, id: @`[FontRes](https://developer.android.com/reference/kotlin/androidx/annotation/FontRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Returns a cached font Typeface associated with a particular resource ID.                                                                                                                                                                                                                                                                                                                                                                   |
| `java-static @`[ColorInt](https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [getColor](https://developer.android.com/reference/kotlin/androidx/core/content/res/ResourcesCompat#getColor(android.content.res.Resources,int,android.content.res.Resources.Theme))`(res: `[Resources](https://developer.android.com/reference/android/content/res/Resources.html)`, id: @`[ColorRes](https://developer.android.com/reference/kotlin/androidx/annotation/ColorRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, theme: `[Resources.Theme](https://developer.android.com/reference/android/content/res/Resources.Theme.html)`?)` Returns a themed color integer associated with a particular resource ID.                                                                                                                                                                                                              |
| `java-static `[ColorStateList](https://developer.android.com/reference/android/content/res/ColorStateList.html)`?`                                                                   | [getColorStateList](https://developer.android.com/reference/kotlin/androidx/core/content/res/ResourcesCompat#getColorStateList(android.content.res.Resources,int,android.content.res.Resources.Theme))`(res: `[Resources](https://developer.android.com/reference/android/content/res/Resources.html)`, id: @`[ColorRes](https://developer.android.com/reference/kotlin/androidx/annotation/ColorRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, theme: `[Resources.Theme](https://developer.android.com/reference/android/content/res/Resources.Theme.html)`?)` Returns a themed color state list associated with a particular resource ID.                                                                                                                                                                                         |
| `java-static `[Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable.html)`?`                                                                         | [getDrawable](https://developer.android.com/reference/kotlin/androidx/core/content/res/ResourcesCompat#getDrawable(android.content.res.Resources,int,android.content.res.Resources.Theme))`(res: `[Resources](https://developer.android.com/reference/android/content/res/Resources.html)`, id: @`[DrawableRes](https://developer.android.com/reference/kotlin/androidx/annotation/DrawableRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, theme: `[Resources.Theme](https://developer.android.com/reference/android/content/res/Resources.Theme.html)`?)` Return a drawable object associated with a particular resource ID and styled for the specified theme.                                                                                                                                                                     |
| `java-static `[Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable.html)`?`                                                                         | [getDrawableForDensity](https://developer.android.com/reference/kotlin/androidx/core/content/res/ResourcesCompat#getDrawableForDensity(android.content.res.Resources,int,int,android.content.res.Resources.Theme))`(` ` res: `[Resources](https://developer.android.com/reference/android/content/res/Resources.html)`,` ` id: @`[DrawableRes](https://developer.android.com/reference/kotlin/androidx/annotation/DrawableRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` density: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` theme: `[Resources.Theme](https://developer.android.com/reference/android/content/res/Resources.Theme.html)`?` `)` Return a drawable object associated with a particular resource ID for the given screen density in DPI and styled for the specified theme. |
| `java-static `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)                                                                                        | [getFloat](https://developer.android.com/reference/kotlin/androidx/core/content/res/ResourcesCompat#getFloat(android.content.res.Resources,int))`(res: `[Resources](https://developer.android.com/reference/android/content/res/Resources.html)`, id: @`[DimenRes](https://developer.android.com/reference/kotlin/androidx/annotation/DimenRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Retrieve a floating-point value for a particular resource ID.                                                                                                                                                                                                                                                                                                                                                                            |
| `java-static `[Typeface](https://developer.android.com/reference/android/graphics/Typeface.html)`?`                                                                                  | [getFont](https://developer.android.com/reference/kotlin/androidx/core/content/res/ResourcesCompat#getFont(android.content.Context,int))`(context: `[Context](https://developer.android.com/reference/android/content/Context.html)`, id: @`[FontRes](https://developer.android.com/reference/kotlin/androidx/annotation/FontRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Returns a font Typeface associated with a particular resource ID.                                                                                                                                                                                                                                                                                                                                                                                      |
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                          | [getFont](https://developer.android.com/reference/kotlin/androidx/core/content/res/ResourcesCompat#getFont(android.content.Context,int,androidx.core.content.res.ResourcesCompat.FontCallback,android.os.Handler))`(` ` context: `[Context](https://developer.android.com/reference/android/content/Context.html)`,` ` id: @`[FontRes](https://developer.android.com/reference/kotlin/androidx/annotation/FontRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` fontCallback: `[ResourcesCompat.FontCallback](https://developer.android.com/reference/kotlin/androidx/core/content/res/ResourcesCompat.FontCallback)`,` ` handler: `[Handler](https://developer.android.com/reference/android/os/Handler.html)`?` `)` Returns a font Typeface associated with a particular resource ID asynchronously.                              |

## Constants

### ID_NULL

Added in[1.3.0](https://developer.android.com/jetpack/androidx/releases/core#1.3.0)  

```
const val ID_NULL = 0: @AnyRes Int
```

The`null`resource ID. This denotes an invalid resource ID that is returned by the system when a resource is not found or the value is set to`@null`in XML.  

## Public functions

### clearCachesForTheme

Added in[1.8.0](https://developer.android.com/jetpack/androidx/releases/core#1.8.0)  

```
java-static fun clearCachesForTheme(theme: Resources.Theme): Unit
```

Clears cached values associated with the specified[Theme](https://developer.android.com/reference/android/content/res/Resources.Theme.html).

This method allows developers to work around issues related to stale cached resources that may occur on API level 32 and below following a call to[applyStyle](https://developer.android.com/reference/android/content/res/Resources.Theme.html#applyStyle(int, boolean)). If you are not explicitly calling`
applyStyle`in your code, you probably do not need to call this method.

Starting in Android T, the Theme class correctly implements[hashCode](https://developer.android.com/reference/android/content/res/Resources.Theme.html#hashCode())and cached values will be appropriately cleared when the contents of a Theme object change.  

|                                                  Parameters                                                  |
|--------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------|
| `theme: `[Resources.Theme](https://developer.android.com/reference/android/content/res/Resources.Theme.html) | the theme for which associated values should be cleared from the resource cache |

### getCachedFont

Added in[1.5.0](https://developer.android.com/jetpack/androidx/releases/core#1.5.0)  

```
java-static fun getCachedFont(context: Context, id: @FontRes Int): Typeface?
```

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

This method returns non-null Typeface if the requested font is already fetched. Otherwise immediately returns null without requesting to font provider.

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.  

|                                                                                 Parameters                                                                                 |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)                                                                                 | A context to retrieve the Resources from.                                                                                                                                                                                                                |
| `id: @`[FontRes](https://developer.android.com/reference/kotlin/androidx/annotation/FontRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | 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. |

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

|                                                                     Throws                                                                      |
|-------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------|
| [android.content.res.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](https://developer.android.com/reference/kotlin/androidx/core/content/res/ResourcesCompat#getFont(android.content.Context,int,androidx.core.content.res.ResourcesCompat.FontCallback,android.os.Handler)) |   |

### getColor

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
java-static fun getColor(res: Resources, id: @ColorRes Int, theme: Resources.Theme?): @ColorInt Int
```

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

|                                                                                  Parameters                                                                                  |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `res: `[Resources](https://developer.android.com/reference/android/content/res/Resources.html)                                                                               | resources to use for getting the color.                                                                                                                           |
| `id: @`[ColorRes](https://developer.android.com/reference/kotlin/androidx/annotation/ColorRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | 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](https://developer.android.com/reference/android/content/res/Resources.Theme.html)`?`                                                              | The theme used to style the color attributes, may be`null`.                                                                                                       |

|                                                                                 Returns                                                                                  |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------|
| `@`[ColorInt](https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | A single color value in the form`0xAARRGGBB`. |

|                                                                     Throws                                                                      |
|-------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------|
| [android.content.res.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[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
java-static fun getColorStateList(res: Resources, id: @ColorRes Int, theme: Resources.Theme?): ColorStateList?
```

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.  

|                                                                                  Parameters                                                                                  |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `res: `[Resources](https://developer.android.com/reference/android/content/res/Resources.html)                                                                               | resources to use for getting the color state list.                                                                                                                                                                                                                      |
| `id: @`[ColorRes](https://developer.android.com/reference/kotlin/androidx/annotation/ColorRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | 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. |
| `theme: `[Resources.Theme](https://developer.android.com/reference/android/content/res/Resources.Theme.html)`?`                                                              | The theme used to style the color attributes, may be`null`.                                                                                                                                                                                                             |

|                                               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. |

|                                                                     Throws                                                                      |
|-------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------|
| [android.content.res.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[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
java-static fun getDrawable(res: Resources, id: @DrawableRes Int, theme: Resources.Theme?): Drawable?
```

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

|                                                                                     Parameters                                                                                     |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `res: `[Resources](https://developer.android.com/reference/android/content/res/Resources.html)                                                                                     | resources to use for getting the drawable.                                                                                                                        |
| `id: @`[DrawableRes](https://developer.android.com/reference/kotlin/androidx/annotation/DrawableRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | 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](https://developer.android.com/reference/android/content/res/Resources.Theme.html)`?`                                                                    | The theme used to style the drawable attributes, may be`null`.                                                                                                    |

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

|                                                                     Throws                                                                      |
|-------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------|
| [android.content.res.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[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
java-static fun getDrawableForDensity(
    res: Resources,
    id: @DrawableRes Int,
    density: Int,
    theme: Resources.Theme?
): Drawable?
```

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](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).  

|                                                                                     Parameters                                                                                     |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `res: `[Resources](https://developer.android.com/reference/android/content/res/Resources.html)                                                                                     | resources to use for getting the drawable.                                                                                                                        |
| `id: @`[DrawableRes](https://developer.android.com/reference/kotlin/androidx/annotation/DrawableRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | 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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                             | The desired screen density indicated by the resource as found in[DisplayMetrics](https://developer.android.com/reference/android/util/DisplayMetrics.html).       |
| `theme: `[Resources.Theme](https://developer.android.com/reference/android/content/res/Resources.Theme.html)`?`                                                                    | The theme used to style the drawable attributes, may be`null`.                                                                                                    |

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

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

### getFloat

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
java-static fun getFloat(res: Resources, id: @DimenRes Int): Float
```

Retrieve a floating-point value for a particular resource ID.  

|                                                                                  Parameters                                                                                  |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `res: `[Resources](https://developer.android.com/reference/android/content/res/Resources.html)                                                                               | resources to use for getting the value.                                                                                                                           |
| `id: @`[DimenRes](https://developer.android.com/reference/kotlin/androidx/annotation/DimenRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | 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. |

|                                     Returns                                     |
|---------------------------------------------------------------------------------|-------------------------------------------------------------|
| [Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | Returns the floating-point value contained in the resource. |

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

### getFont

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
java-static fun getFont(context: Context, id: @FontRes Int): Typeface?
```

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](https://developer.android.com/reference/kotlin/androidx/core/content/res/ResourcesCompat#getFont(android.content.Context,int,androidx.core.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.  

|                                                                                 Parameters                                                                                 |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)                                                                                 | A context to retrieve the Resources from.                                                                                                                                                                                                                |
| `id: @`[FontRes](https://developer.android.com/reference/kotlin/androidx/annotation/FontRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | 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. |

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

|                                                                     Throws                                                                      |
|-------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------|
| [android.content.res.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](https://developer.android.com/reference/kotlin/androidx/core/content/res/ResourcesCompat#getFont(android.content.Context,int,androidx.core.content.res.ResourcesCompat.FontCallback,android.os.Handler)) |   |

### getFont

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)  

```
java-static fun getFont(
    context: Context,
    id: @FontRes Int,
    fontCallback: ResourcesCompat.FontCallback,
    handler: Handler?
): Unit
```

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.  

|                                                                                 Parameters                                                                                 |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context: `[Context](https://developer.android.com/reference/android/content/Context.html)                                                                                 | A context to retrieve the Resources from.                                                                                                                                                                                                                |
| `id: @`[FontRes](https://developer.android.com/reference/kotlin/androidx/annotation/FontRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | 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. |
| `fontCallback: `[ResourcesCompat.FontCallback](https://developer.android.com/reference/kotlin/androidx/core/content/res/ResourcesCompat.FontCallback)                      | A callback to receive async fetching of this font. The callback will be triggered on the UI thread.                                                                                                                                                      |
| `handler: `[Handler](https://developer.android.com/reference/android/os/Handler.html)`?`                                                                                   | A handler for the thread the callback should be called on. If null, the callback will be called on the UI thread.                                                                                                                                        |

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