TypefaceCompat

Added in 1.1.0

public class TypefaceCompat


Helper for accessing features in Typeface.

Summary

Public methods

static @NonNull Typeface
create(@NonNull Context context, @Nullable Typeface family, int style)

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

static @NonNull Typeface
create(
    @NonNull Context context,
    @Nullable Typeface family,
    @IntRange(from = 1, to = 1000) int weight,
    boolean italic
)

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

Public methods

create

Added in 1.1.0
public static @NonNull Typeface create(@NonNull Context context, @Nullable Typeface family, int style)

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
@NonNull Context context

The context used to retrieve the font.

@Nullable Typeface family

The font family. May be null.

int style

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

Returns
@NonNull Typeface

The best matching typeface.

create

Added in 1.9.0
public static @NonNull Typeface create(
    @NonNull Context context,
    @Nullable Typeface family,
    @IntRange(from = 1, to = 1000) int weight,
    boolean italic
)

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
@NonNull Context context

context to use for the creation.

@Nullable Typeface family

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

@IntRange(from = 1, to = 1000) int weight

The desired weight to be drawn.

boolean italic

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

Returns
@NonNull Typeface

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

See also
getWeight
isItalic