ColorScheme

class ColorScheme


A color scheme holds all the named color parameters for a MaterialTheme.

Color schemes are designed to be harmonious, ensure accessible text, and distinguish UI elements and surfaces from one another. There are two built-in baseline schemes, lightColorScheme and a darkColorScheme, that can be used as-is or customized.

The Material color system and custom schemes provide default values for color as a starting point for customization.

To learn more about colors, see Material Design colors.

Summary

Public constructors

ColorScheme(
    primary: Color,
    onPrimary: Color,
    primaryContainer: Color,
    onPrimaryContainer: Color,
    inversePrimary: Color,
    secondary: Color,
    onSecondary: Color,
    secondaryContainer: Color,
    onSecondaryContainer: Color,
    tertiary: Color,
    onTertiary: Color,
    tertiaryContainer: Color,
    onTertiaryContainer: Color,
    background: Color,
    onBackground: Color,
    surface: Color,
    onSurface: Color,
    surfaceVariant: Color,
    onSurfaceVariant: Color,
    surfaceTint: Color,
    inverseSurface: Color,
    inverseOnSurface: Color,
    error: Color,
    onError: Color,
    errorContainer: Color,
    onErrorContainer: Color,
    border: Color,
    borderVariant: Color,
    scrim: Color
)

Public functions

ColorScheme
copy(
    primary: Color,
    onPrimary: Color,
    primaryContainer: Color,
    onPrimaryContainer: Color,
    inversePrimary: Color,
    secondary: Color,
    onSecondary: Color,
    secondaryContainer: Color,
    onSecondaryContainer: Color,
    tertiary: Color,
    onTertiary: Color,
    tertiaryContainer: Color,
    onTertiaryContainer: Color,
    background: Color,
    onBackground: Color,
    surface: Color,
    onSurface: Color,
    surfaceVariant: Color,
    onSurfaceVariant: Color,
    surfaceTint: Color,
    inverseSurface: Color,
    inverseOnSurface: Color,
    error: Color,
    onError: Color,
    errorContainer: Color,
    onErrorContainer: Color,
    border: Color,
    borderVariant: Color,
    scrim: Color
)

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

open String

Public properties

Color

The background color that appears behind scrollable content.

Color

Subtle color used for boundaries.

Color

Utility color used for boundaries for decorative elements when strong contrast is not required.

Color

The error color is used to indicate errors in components, such as invalid text in a text field.

Color

The preferred tonal color of error containers.

Color

A color that contrasts well with inverseSurface.

Color

Color to be used as a "primary" color in places where the inverse color scheme is needed, such as the button on a SnackBar.

Color

A color that contrasts sharply with surface.

Color

Color used for text and icons displayed on top of the background color.

Color

Color used for text and icons displayed on top of the error color.

Color

The color (and state variants) that should be used for content on top of errorContainer.

Color

Color used for text and icons displayed on top of the primary color.

Color

The color (and state variants) that should be used for content on top of primaryContainer.

Color

Color used for text and icons displayed on top of the secondary color.

Color

The color (and state variants) that should be used for content on top of secondaryContainer.

Color

Color used for text and icons displayed on top of the surface color.

Color

The color (and state variants) that can be used for content on top of surface.

Color

Color used for text and icons displayed on top of the tertiary color.

Color

The color (and state variants) that should be used for content on top of tertiaryContainer.

Color

The primary color is the color displayed most frequently across your app’s screens and components.

Color

The preferred tonal color of containers.

Color

Color of a scrim that obscures content.

Color

The secondary color provides more ways to accent and distinguish your product.

Color

A tonal color to be used in containers.

Color

The surface color that affect surfaces of components, such as cards, sheets, and menus.

Color

This color will be used by components that apply tonal elevation and is applied on top of surface.

Color

Another option for a color with similar uses of surface.

Color

The tertiary color that can be used to balance primary and secondary colors, or bring heightened attention to an element such as an input field.

Color

A tonal color to be used in containers.

Extension functions

Color
ColorScheme.contentColorFor(backgroundColor: Color)

The Material color system contains pairs of colors that are typically used for the background and content color inside a component.

Color

Computes the surface tonal color at different elevation levels e.g. surface1 through surface5.

Public constructors

ColorScheme

Added in 1.1.0
ColorScheme(
    primary: Color,
    onPrimary: Color,
    primaryContainer: Color,
    onPrimaryContainer: Color,
    inversePrimary: Color,
    secondary: Color,
    onSecondary: Color,
    secondaryContainer: Color,
    onSecondaryContainer: Color,
    tertiary: Color,
    onTertiary: Color,
    tertiaryContainer: Color,
    onTertiaryContainer: Color,
    background: Color,
    onBackground: Color,
    surface: Color,
    onSurface: Color,
    surfaceVariant: Color,
    onSurfaceVariant: Color,
    surfaceTint: Color,
    inverseSurface: Color,
    inverseOnSurface: Color,
    error: Color,
    onError: Color,
    errorContainer: Color,
    onErrorContainer: Color,
    border: Color,
    borderVariant: Color,
    scrim: Color
)

Public functions

copy

Added in 1.1.0
fun copy(
    primary: Color = this.primary,
    onPrimary: Color = this.onPrimary,
    primaryContainer: Color = this.primaryContainer,
    onPrimaryContainer: Color = this.onPrimaryContainer,
    inversePrimary: Color = this.inversePrimary,
    secondary: Color = this.secondary,
    onSecondary: Color = this.onSecondary,
    secondaryContainer: Color = this.secondaryContainer,
    onSecondaryContainer: Color = this.onSecondaryContainer,
    tertiary: Color = this.tertiary,
    onTertiary: Color = this.onTertiary,
    tertiaryContainer: Color = this.tertiaryContainer,
    onTertiaryContainer: Color = this.onTertiaryContainer,
    background: Color = this.background,
    onBackground: Color = this.onBackground,
    surface: Color = this.surface,
    onSurface: Color = this.onSurface,
    surfaceVariant: Color = this.surfaceVariant,
    onSurfaceVariant: Color = this.onSurfaceVariant,
    surfaceTint: Color = this.surfaceTint,
    inverseSurface: Color = this.inverseSurface,
    inverseOnSurface: Color = this.inverseOnSurface,
    error: Color = this.error,
    onError: Color = this.onError,
    errorContainer: Color = this.errorContainer,
    onErrorContainer: Color = this.onErrorContainer,
    border: Color = this.border,
    borderVariant: Color = this.borderVariant,
    scrim: Color = this.scrim
): ColorScheme

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

toString

open fun toString(): String

Public properties

background

Added in 1.0.0
val background: Color

The background color that appears behind scrollable content.

border

Added in 1.0.0
val border: Color

Subtle color used for boundaries. Border color role adds contrast for accessibility purposes.

borderVariant

Added in 1.0.0
val borderVariant: Color

Utility color used for boundaries for decorative elements when strong contrast is not required.

error

Added in 1.0.0
val error: Color

The error color is used to indicate errors in components, such as invalid text in a text field.

errorContainer

Added in 1.0.0
val errorContainer: Color

The preferred tonal color of error containers.

inverseOnSurface

Added in 1.0.0
val inverseOnSurface: Color

A color that contrasts well with inverseSurface. Useful for content that sits on top of containers that are inverseSurface.

inversePrimary

Added in 1.0.0
val inversePrimary: Color

Color to be used as a "primary" color in places where the inverse color scheme is needed, such as the button on a SnackBar.

inverseSurface

Added in 1.0.0
val inverseSurface: Color

A color that contrasts sharply with surface. Useful for surfaces that sit on top of other surfaces with surface color.

onBackground

Added in 1.0.0
val onBackground: Color

Color used for text and icons displayed on top of the background color.

onError

Added in 1.0.0
val onError: Color

Color used for text and icons displayed on top of the error color.

onErrorContainer

Added in 1.0.0
val onErrorContainer: Color

The color (and state variants) that should be used for content on top of errorContainer.

onPrimary

Added in 1.0.0
val onPrimary: Color

Color used for text and icons displayed on top of the primary color.

onPrimaryContainer

Added in 1.0.0
val onPrimaryContainer: Color

The color (and state variants) that should be used for content on top of primaryContainer.

onSecondary

Added in 1.0.0
val onSecondary: Color

Color used for text and icons displayed on top of the secondary color.

onSecondaryContainer

Added in 1.0.0
val onSecondaryContainer: Color

The color (and state variants) that should be used for content on top of secondaryContainer.

onSurface

Added in 1.0.0
val onSurface: Color

Color used for text and icons displayed on top of the surface color.

onSurfaceVariant

Added in 1.0.0
val onSurfaceVariant: Color

The color (and state variants) that can be used for content on top of surface.

onTertiary

Added in 1.0.0
val onTertiary: Color

Color used for text and icons displayed on top of the tertiary color.

onTertiaryContainer

Added in 1.0.0
val onTertiaryContainer: Color

The color (and state variants) that should be used for content on top of tertiaryContainer.

primary

Added in 1.0.0
val primary: Color

The primary color is the color displayed most frequently across your app’s screens and components.

primaryContainer

Added in 1.0.0
val primaryContainer: Color

The preferred tonal color of containers.

scrim

Added in 1.0.0
val scrim: Color

Color of a scrim that obscures content.

secondary

Added in 1.0.0
val secondary: Color

The secondary color provides more ways to accent and distinguish your product. Secondary colors are best for:

  • Floating action buttons

  • Selection controls, like checkboxes and radio buttons

  • Highlighting selected text

  • Links and headlines

secondaryContainer

Added in 1.0.0
val secondaryContainer: Color

A tonal color to be used in containers.

surface

Added in 1.0.0
val surface: Color

The surface color that affect surfaces of components, such as cards, sheets, and menus.

surfaceTint

Added in 1.0.0
val surfaceTint: Color

This color will be used by components that apply tonal elevation and is applied on top of surface. The higher the elevation the more this color is used.

surfaceVariant

Added in 1.0.0
val surfaceVariant: Color

Another option for a color with similar uses of surface.

tertiary

Added in 1.0.0
val tertiary: Color

The tertiary color that can be used to balance primary and secondary colors, or bring heightened attention to an element such as an input field.

tertiaryContainer

Added in 1.0.0
val tertiaryContainer: Color

A tonal color to be used in containers.

Extension functions

ColorScheme.contentColorFor

fun ColorScheme.contentColorFor(backgroundColor: Color): Color

The Material color system contains pairs of colors that are typically used for the background and content color inside a component. For example, a Button typically uses primary for its background, and onPrimary for the color of its content (usually text or iconography).

This function tries to match the provided backgroundColor to a 'background' color in this ColorScheme, and then will return the corresponding color used for content. For example, when backgroundColor is ColorScheme.primary, this will return ColorScheme.onPrimary.

If backgroundColor does not match a background color in the theme, this will return Color.Unspecified.

Returns
Color

the matching content color for backgroundColor. If backgroundColor is not present in the theme's ColorScheme, then returns Color.Unspecified.

See also
contentColorFor

ColorScheme.surfaceColorAtElevation

fun ColorScheme.surfaceColorAtElevation(elevation: Dp): Color

Computes the surface tonal color at different elevation levels e.g. surface1 through surface5.

Parameters
elevation: Dp

Elevation value used to compute alpha of the color overlay layer.

Returns
Color

the ColorScheme.surface color with an alpha of the ColorScheme.surfaceTint color overlaid on top of it.