Google se compromete a impulsar la igualdad racial para las comunidades afrodescendientes. Obtén información al respecto.

ResourcesCompat

class ResourcesCompat
kotlin.Any
   ↳ androidx.core.content.res.ResourcesCompat

Helper for accessing features in android.content.res.Resources.

Summary

Nested classes
abstract

Interface used to receive asynchronous font fetching events.

Provides backward-compatible implementations for new Theme APIs.

Constants
static Int

The null resource ID.

Public methods
static Typeface?
getCachedFont(@NonNull context: Context, @FontRes id: Int)

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

static Int
getColor(@NonNull res: Resources, @ColorRes id: Int, @Nullable theme: Theme?)

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

static ColorStateList?
getColorStateList(@NonNull res: Resources, @ColorRes id: Int, @Nullable theme: Theme?)

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

static Drawable?
getDrawable(@NonNull res: Resources, @DrawableRes id: Int, @Nullable theme: Theme?)

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

static Drawable?
getDrawableForDensity(@NonNull res: Resources, @DrawableRes id: Int, density: Int, @Nullable 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.

static Float
getFloat(@NonNull res: Resources, @DimenRes id: Int)

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

static Typeface?
getFont(@NonNull context: Context, @FontRes id: Int)

Returns a font Typeface associated with a particular resource ID.

static Unit
getFont(@NonNull context: Context, @FontRes id: Int, @NonNull fontCallback: ResourcesCompat.FontCallback, @Nullable handler: Handler?)

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

Constants

ID_NULL

@AnyRes static val ID_NULL: 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.

Value: 0

Public methods

getCachedFont

@Nullable static fun getCachedFont(
    @NonNull context: Context,
    @FontRes id: 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: A context to retrieve the Resources from.
id Int: The desired resource identifier of a Typeface, as generated by the aapt tool. This integer encodes the package, type, and resource entry. The value 0 is an invalid identifier.
Return
Typeface? A font Typeface object.
Exceptions
NotFoundException Throws NotFoundException if the given ID does not exist.

getColor

@ColorInt static fun getColor(
    @NonNull res: Resources,
    @ColorRes id: Int,
    @Nullable theme: Theme