FontStyle


public final class FontStyle
extends Object

java.lang.Object
   ↳ android.graphics.fonts.FontStyle


A font style object. This class represents a single font style which is a pair of weight value and slant value. Here are common font styles examples:

 
 final FontStyle NORMAL = new FontStyle(FONT_WEIGHT_NORMAL, FONT_SLANT_UPRIGHT);
 final FontStyle BOLD = new FontStyle(FONT_WEIGHT_BOLD, FONT_SLANT_UPRIGHT);
 final FontStyle ITALIC = new FontStyle(FONT_WEIGHT_NORMAL, FONT_SLANT_ITALIC);
 final FontStyle BOLD_ITALIC = new FontStyle(FONT_WEIGHT_BOLD, FONT_SLANT_ITALIC);
 
 

Summary

Constants

int FONT_SLANT_ITALIC

A font slant value for italic

int FONT_SLANT_UPRIGHT

A font slant value for upright

int FONT_WEIGHT_BLACK

A font weight value for the black weight

int FONT_WEIGHT_BOLD

A font weight value for the bold weight.

int FONT_WEIGHT_EXTRA_BOLD

A font weight value for the extra-bold weight

int FONT_WEIGHT_EXTRA_LIGHT

A font weight value for the extra-light weight

int FONT_WEIGHT_LIGHT

A font weight value for the light weight

int FONT_WEIGHT_MAX

A maximum weight value for the font

int FONT_WEIGHT_MEDIUM

A font weight value for the medium weight

int FONT_WEIGHT_MIN

A minimum weight value for the font

int FONT_WEIGHT_NORMAL

A font weight value for the normal weight

int FONT_WEIGHT_SEMI_BOLD

A font weight value for the semi-bold weight

int FONT_WEIGHT_THIN

A font weight value for the thin weight

int FONT_WEIGHT_UNSPECIFIED

A default value when font weight is unspecified

Public constructors

FontStyle()
FontStyle(int weight, int slant)

Create FontStyle with specific weight and italic

Value Name Android Definition
100 Thin FontStyle.FONT_WEIGHT_THIN
200 Extra Light (Ultra Light) FontStyle.FONT_WEIGHT_EXTRA_LIGHT
300 Light FontStyle.FONT_WEIGHT_LIGHT
400 Normal (Regular) FontStyle.FONT_WEIGHT_NORMAL
500 Medium FontStyle.FONT_WEIGHT_MEDIUM
600 Semi Bold (Demi Bold) FontStyle.FONT_WEIGHT_SEMI_BOLD
700 Bold FontStyle.FONT_WEIGHT_BOLD
800 Extra Bold (Ultra Bold) FontStyle.FONT_WEIGHT_EXTRA_BOLD
900 Black (Heavy) FontStyle.FONT_WEIGHT_BLACK

Public methods

boolean equals(Object o)

Indicates whether some other object is "equal to" this one.

int getSlant()

Gets the slant value

int getWeight()

Gets the weight value

int hashCode()

Returns a hash code value for the object.

String toString()

Returns a string representation of the object.

Inherited methods

Constants

FONT_SLANT_ITALIC

Added in API level 29
public static final int FONT_SLANT_ITALIC

A font slant value for italic

Constant Value: 1 (0x00000001)

FONT_SLANT_UPRIGHT

Added in API level 29
public static final int FONT_SLANT_UPRIGHT

A font slant value for upright

Constant Value: 0 (0x00000000)

FONT_WEIGHT_BLACK

Added in API level 29
public static final int FONT_WEIGHT_BLACK

A font weight value for the black weight

Constant Value: 900 (0x00000384)

FONT_WEIGHT_BOLD

Added in API level 29
public static final int FONT_WEIGHT_BOLD

A font weight value for the bold weight.

Constant Value: 700 (0x000002bc)

FONT_WEIGHT_EXTRA_BOLD

Added in API level 29
public static final int FONT_WEIGHT_EXTRA_BOLD

A font weight value for the extra-bold weight

Constant Value: 800 (0x00000320)

FONT_WEIGHT_EXTRA_LIGHT

Added in API level 29
public static final int FONT_WEIGHT_EXTRA_LIGHT

A font weight value for the extra-light weight

Constant Value: 200 (0x000000c8)

FONT_WEIGHT_LIGHT

Added in API level 29
public static final int FONT_WEIGHT_LIGHT

A font weight value for the light weight

Constant Value: 300 (0x0000012c)

FONT_WEIGHT_MAX

Added in API level 29
public static final int FONT_WEIGHT_MAX

A maximum weight value for the font

Constant Value: 1000 (0x000003e8)

FONT_WEIGHT_MEDIUM

Added in API level 29
public static final int FONT_WEIGHT_MEDIUM

A font weight value for the medium weight

Constant Value: 500 (0x000001f4)

FONT_WEIGHT_MIN

Added in API level 29
public static final int FONT_WEIGHT_MIN

A minimum weight value for the font

Constant Value: 1 (0x00000001)

FONT_WEIGHT_NORMAL

Added in API level 29
public static final int FONT_WEIGHT_NORMAL

A font weight value for the normal weight

Constant Value: 400 (0x00000190)

FONT_WEIGHT_SEMI_BOLD

Added in API level 29
public static final int FONT_WEIGHT_SEMI_BOLD

A font weight value for the semi-bold weight

Constant Value: 600 (0x00000258)

FONT_WEIGHT_THIN

Added in API level 29
public static final int FONT_WEIGHT_THIN

A font weight value for the thin weight

Constant Value: 100 (0x00000064)

FONT_WEIGHT_UNSPECIFIED

Added in API level 34
public static final int FONT_WEIGHT_UNSPECIFIED

A default value when font weight is unspecified

Constant Value: -1 (0xffffffff)

Public constructors

FontStyle

Added in API level 29
public FontStyle ()

FontStyle

Added in API level 29
public FontStyle (int weight, 
                int slant)

Create FontStyle with specific weight and italic

Value Name Android Definition
100 Thin FontStyle.FONT_WEIGHT_THIN
200 Extra Light (Ultra Light) FontStyle.FONT_WEIGHT_EXTRA_LIGHT
300 Light FontStyle.FONT_WEIGHT_LIGHT
400 Normal (Regular) FontStyle.FONT_WEIGHT_NORMAL
500 Medium FontStyle.FONT_WEIGHT_MEDIUM
600 Semi Bold (Demi Bold) FontStyle.FONT_WEIGHT_SEMI_BOLD
700 Bold FontStyle.FONT_WEIGHT_BOLD
800 Extra Bold (Ultra Bold) FontStyle.FONT_WEIGHT_EXTRA_BOLD
900 Black (Heavy) FontStyle.FONT_WEIGHT_BLACK
Parameters
weight int: a weight value

slant int: a slant value Value is FONT_SLANT_UPRIGHT, or FONT_SLANT_ITALIC

Public methods

equals

Added in API level 29
public boolean equals (Object o)

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o Object: This value may be null.

Returns
boolean true if this object is the same as the obj argument; false otherwise.

getSlant

Added in API level 29
public int getSlant ()

Gets the slant value

Returns
int a slant value Value is FONT_SLANT_UPRIGHT, or FONT_SLANT_ITALIC

getWeight

Added in API level 29
public int getWeight ()

Gets the weight value

Returns
int a weight value Value is between 0 and 1000 inclusive

hashCode

Added in API level 29
public int hashCode ()

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.

Returns
int a hash code value for this object.

toString

Added in API level 29
public String toString ()

Returns a string representation of the object.

Returns
String a string representation of the object.