getFont

@Nullable
open fun getFont(@NonNull context: @NonNull Context, @FontRes id: Int): @Nullable Typeface(source)

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

Return

A font Typeface object.

Parameters

context

A context to retrieve the Resources from.

id

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.

See also

Throws

Throws NotFoundException if the given ID does not exist.


open fun getFont(@NonNull context: @NonNull Context, @FontRes id: Int, @NonNull fontCallback: @NonNull ResourcesCompat.FontCallback, @Nullable handler: @Nullable Handler)(source)

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

A context to retrieve the Resources from.

id

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.

fontCallback

A callback to receive async fetching of this font. The callback will be triggered on the UI thread.

handler

A handler for the thread the callback should be called on. If null, the callback will be called on the UI thread.

Throws

Throws NotFoundException if the given ID does not exist.


@Nullable
open fun getFont(@NonNull context: @NonNull Context, @FontRes id: Int, @NonNull value: @NonNull TypedValue, style: Int, @Nullable fontCallback: @Nullable ResourcesCompat.FontCallback): @Nullable Typeface(source)

Used by TintTypedArray.