TypefaceCompat

Added in 1.1.0

class TypefaceCompat


Helper for accessing features in Typeface.

Summary

Public functions

java-static Typeface
create(context: Context, family: Typeface?, style: Int)

Retrieves the best matching typeface given the family, style and context.

java-static Typeface
create(
    context: Context,
    family: Typeface?,
    weight: @IntRange(from = 1, to = 1000) Int,
    italic: Boolean
)

Creates a typeface object that best matches the specified existing typeface and the specified weight and italic style

Public functions

create

Added in 1.1.0
java-static fun create(context: Context, family: Typeface?, style: Int): Typeface

Retrieves the best matching typeface given the family, style and context. If null is passed for the family, then the "default" font will be chosen.

Parameters
context: Context

The context used to retrieve the font.

family: Typeface?

The font family. May be null.

style: Int

The style of the typeface. e.g. NORMAL, BOLD, ITALIC, BOLD_ITALIC

Returns
Typeface

The best matching typeface.

create

Added in 1.9.0
java-static fun create(
    context: Context,
    family: Typeface?,
    weight: @IntRange(from = 1, to = 1000) Int,
    italic: Boolean
): Typeface

Creates a typeface object that best matches the specified existing typeface and the specified weight and italic style

Below are numerical values and corresponding common weight names.

Value Common weight name
100 Thin
200 Extra Light
300 Light
400 Normal
500 Medium
600 Semi Bold
700 Bold
800 Extra Bold
900 Black

This method is thread safe.

Parameters
context: Context

context to use for the creation.

family: Typeface?

An existing Typeface object. In case of null, the default typeface is used instead.

weight: @IntRange(from = 1, to = 1000) Int

The desired weight to be drawn.

italic: Boolean

true if italic style is desired to be drawn. Otherwise, false

Returns
Typeface

A Typeface object for drawing specified weight and italic style. Never returns null

See also
getWeight
isItalic