Typography

Class

Common
class Typography
internal constructor(
    val h1: TextStyle,
    val h2: TextStyle,
    val h3: TextStyle,
    val h4: TextStyle,
    val h5: TextStyle,
    val h6: TextStyle,
    val subtitle1: TextStyle,
    val subtitle2: TextStyle,
    val body1: TextStyle,
    val body2: TextStyle,
    val button: TextStyle,
    val caption: TextStyle,
    val overline: TextStyle,
)

Material Design type scale(https://material.io/design/typography/the-type-system.html#type-scale)

The Material Design type scale includes a range of contrasting styles that support the needs of your product and its content.

The type scale is a combination of thirteen styles that are supported by the type system. It contains reusable categories of text, each with an intended application and meaning.

!Typography image(https://developer.android.com/images/reference/androidx/compose/material/typography.png)

Secondary Constructors

constructor(
    defaultFontFamily: FontFamily = FontFamily.Default,
    h1: TextStyle =
        DefaultTextStyle.copy(
            fontWeight = FontWeight.Light,
            fontSize = 96.sp,
            lineHeight = 112.sp,
            letterSpacing = (-1.5).sp,
        ),
    h2: TextStyle =
        DefaultTextStyle.copy(
            fontWeight = FontWeight.Light,
            fontSize = 60.sp,
            lineHeight = 72.sp,
            letterSpacing = (-0.5).sp,
        ),
    h3: TextStyle =
        DefaultTextStyle.copy(
            fontWeight = FontWeight.Normal,
            fontSize = 48.sp,
            lineHeight = 56.sp,
            letterSpacing = 0.sp,
        ),
    h4: TextStyle =
        DefaultTextStyle.copy(
            fontWeight = FontWeight.Normal,
            fontSize = 34.sp,
            lineHeight = 36.sp,
            letterSpacing = 0.25.sp,
        ),
    h5: TextStyle =
        DefaultTextStyle.copy(
            fontWeight = FontWeight.Normal,
            fontSize = 24.sp,
            lineHeight = 24.sp,
            letterSpacing = 0.sp,
        ),
    h6: TextStyle =
        DefaultTextStyle.copy(
            fontWeight = FontWeight.Medium,
            fontSize = 20.sp,
            lineHeight = 24.sp,
            letterSpacing = 0.15.sp,
        ),
    subtitle1: TextStyle =
        DefaultTextStyle.copy(
            fontWeight = FontWeight.Normal,
            fontSize = 16.sp,
            lineHeight = 24.sp,
            letterSpacing = 0.15.sp,
        ),
    subtitle2: TextStyle =
        DefaultTextStyle.copy(
            fontWeight = FontWeight.Medium,
            fontSize = 14.sp,
            lineHeight = 24.sp,
            letterSpacing = 0.1.sp,
        ),
    body1: TextStyle =
        DefaultTextStyle.copy(
            fontWeight = FontWeight.Normal,
            fontSize = 16.sp,
            lineHeight = 24.sp,
            letterSpacing = 0.5.sp,
        ),
    body2: TextStyle =
        DefaultTextStyle.copy(
            fontWeight = FontWeight.Normal,
            fontSize = 14.sp,
            lineHeight = 20.sp,
            letterSpacing = 0.25.sp,
        ),
    button: TextStyle =
        DefaultTextStyle.copy(
            fontWeight = FontWeight.Medium,
            fontSize = 14.sp,
            lineHeight = 16.sp,
            letterSpacing = 1.25.sp,
        ),
    caption: TextStyle =
        DefaultTextStyle.copy(
            fontWeight = FontWeight.Normal,
            fontSize = 12.sp,
            lineHeight = 16.sp,
            letterSpacing = 0.4.sp,
        ),
    overline: TextStyle =
        DefaultTextStyle.copy(
            fontWeight = FontWeight.Normal,
            fontSize = 10.sp,
            lineHeight = 16.sp,
            letterSpacing = 1.5.sp,
        ),
) : this(
    h1 = h1.withDefaultFontFamily(defaultFontFamily),
    h2 = h2.withDefaultFontFamily(defaultFontFamily),
    h3 = h3.withDefaultFontFamily(defaultFontFamily),
    h4 = h4.withDefaultFontFamily(defaultFontFamily),
    h5 = h5.withDefaultFontFamily(defaultFontFamily),
    h6 = h6.withDefaultFontFamily(defaultFontFamily),
    subtitle1 = subtitle1.withDefaultFontFamily(defaultFontFamily),
    subtitle2 = subtitle2.withDefaultFontFamily(defaultFontFamily),
    body1 = body1.withDefaultFontFamily(defaultFontFamily),
    body2 = body2.withDefaultFontFamily(defaultFontFamily),
    button = button.withDefaultFontFamily(defaultFontFamily),
    caption = caption.withDefaultFontFamily(defaultFontFamily),
    overline = overline.withDefaultFontFamily(defaultFontFamily),
)

Constructor to create a Typography. For information on the types of style defined in this constructor, see the property documentation for Typography.

Parameters

defaultFontFamilythe default FontFamily to be used for TextStyles provided in this constructor. This default will be used if the FontFamily on the TextStyle is null.
h1h1 is the largest headline, reserved for short, important text or numerals.
h2h2 is the second largest headline, reserved for short, important text or numerals.
h3h3 is the third largest headline, reserved for short, important text or numerals.
h4h4 is the fourth largest headline, reserved for short, important text or numerals.
h5h5 is the fifth largest headline, reserved for short, important text or numerals.
h6h6 is the sixth largest headline, reserved for short, important text or numerals.
subtitle1subtitle1 is the largest subtitle, and is typically reserved for medium-emphasis text that is shorter in length.
subtitle2subtitle2 is the smallest subtitle, and is typically reserved for medium-emphasis text that is shorter in length.
body1body1 is the largest body, and is typically used for long-form writing as it works well for small text sizes.
body2body2 is the smallest body, and is typically used for long-form writing as it works well for small text sizes.
buttonbutton text is a call to action used in different types of buttons (such as text, outlined and contained buttons) and in tabs, dialogs, and cards.
captioncaption is one of the smallest font sizes. It is used sparingly to annotate imagery or to introduce a headline.
overlineoverline is one of the smallest font sizes. It is used sparingly to annotate imagery or to introduce a headline.

Functions

fun copy(
        h1: TextStyle = this.h1,
        h2: TextStyle = this.h2,
        h3: TextStyle = this.h3,
        h4: TextStyle = this.h4,
        h5: TextStyle = this.h5,
        h6: TextStyle = this.h6,
        subtitle1: TextStyle = this.subtitle1,
        subtitle2: TextStyle = this.subtitle2,
        body1: TextStyle = this.body1,
        body2: TextStyle = this.body2,
        button: TextStyle = this.button,
        caption: TextStyle = this.caption,
        overline: TextStyle = this.overline,
    ): Typography

Returns a copy of this Typography, optionally overriding some of the values.