class ColorScheme


A ColorScheme 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.

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

To learn more about color schemes, see Material Design Color System.

Summary

Public constructors

ColorScheme(
    primary: Color,
    primaryDim: Color,
    primaryContainer: Color,
    onPrimary: Color,
    onPrimaryContainer: Color,
    secondary: Color,
    secondaryDim: Color,
    secondaryContainer: Color,
    onSecondary: Color,
    onSecondaryContainer: Color,
    tertiary: Color,
    tertiaryDim: Color,
    tertiaryContainer: Color,
    onTertiary: Color,
    onTertiaryContainer: Color,
    surfaceDim: Color,
    surface: Color,
    surfaceBright: Color,
    onSurface: Color,
    onSurfaceVariant: Color,
    outline: Color,
    outlineVariant: Color,
    background: Color,
    onBackground: Color,
    error: Color,
    onError: Color
)

Public functions

ColorScheme
copy(
    primary: Color,
    primaryDim: Color,
    primaryContainer: Color,
    onPrimary: Color,
    onPrimaryContainer: Color,
    secondary: Color,
    secondaryDim: Color,
    secondaryContainer: Color,
    onSecondary: Color,
    onSecondaryContainer: Color,
    tertiary: Color,
    tertiaryDim: Color,
    tertiaryContainer: Color,
    onTertiary: Color,
    onTertiaryContainer: Color,
    surfaceDim: Color,
    surface: Color,
    surfaceBright: Color,
    onSurface: Color,
    onSurfaceVariant: Color,
    outline: Color,
    outlineVariant: Color,
    background: Color,
    onBackground: Color,
    error: Color,
    onError: Color
)

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

open String

Public properties

Color

The background color that appears behind other content.

Color

The error color is used to indicate errors.

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

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 for secondary text and icons 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 main color for primary outline components.

Color

The secondary color for secondary outline components.

Color

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

Color

is a standout container color for key components.

Color

is less prominent than primary for component backgrounds

Color

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

Color

A tonal color to be used in containers.

Color

is less prominent than secondary for component backgrounds.

Color

The main surface color that affect surfaces of components with large containment areas, such as Card and Button.

Color

A surface color used for large containment components such Card and Button with high prominence.

Color

A surface color used for large containment components such as Card and Button with low prominence.

Color

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

Color

A tonal color to be used in containers.

Color

A less prominent tertiary color that can be used to balance primary and secondary colors, or bring heightened attention to an element.

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.

Public constructors

ColorScheme

ColorScheme(
    primary: Color = ColorTokens.Primary,
    primaryDim: Color = ColorTokens.PrimaryDim,
    primaryContainer: Color = ColorTokens.PrimaryContainer,
    onPrimary: Color = ColorTokens.OnPrimary,
    onPrimaryContainer: Color = ColorTokens.OnPrimaryContainer,
    secondary: Color = ColorTokens.Secondary,
    secondaryDim: Color = ColorTokens.SecondaryDim,
    secondaryContainer: Color = ColorTokens.SecondaryContainer,
    onSecondary: Color = ColorTokens.OnSecondary,
    onSecondaryContainer: Color = ColorTokens.OnSecondaryContainer,
    tertiary: Color = ColorTokens.Tertiary,
    tertiaryDim: Color = ColorTokens.TertiaryDim,
    tertiaryContainer: Color = ColorTokens.TertiaryContainer,
    onTertiary: Color = ColorTokens.OnTertiary,
    onTertiaryContainer: Color = ColorTokens.OnTertiaryContainer,
    surfaceDim: Color = ColorTokens.SurfaceDim,
    surface: Color = ColorTokens.Surface,
    surfaceBright: Color = ColorTokens.SurfaceBright,
    onSurface: Color = ColorTokens.OnSurface,
    onSurfaceVariant: Color = ColorTokens.OnSurfaceVariant,
    outline: Color = ColorTokens.Outline,
    outlineVariant: Color = ColorTokens.OutlineVariant,
    background: Color = ColorTokens.Background,
    onBackground: Color = ColorTokens.OnBackground,
    error: Color = ColorTokens.Error,
    onError: Color = ColorTokens.OnError
)

Public functions

copy

fun copy(
    primary: Color = this.primary,
    primaryDim: Color = this.primaryDim,
    primaryContainer: Color = this.primaryContainer,
    onPrimary: Color = this.onPrimary,
    onPrimaryContainer: Color = this.onPrimaryContainer,
    secondary: Color = this.secondary,
    secondaryDim: Color = this.secondaryDim,
    secondaryContainer: Color = this.secondaryContainer,
    onSecondary: Color = this.onSecondary,
    onSecondaryContainer: Color = this.onSecondaryContainer,
    tertiary: Color = this.tertiary,
    tertiaryDim: Color = this.tertiaryDim,
    tertiaryContainer: Color = this.tertiaryContainer,
    onTertiary: Color = this.onTertiary,
    onTertiaryContainer: Color = this.onTertiaryContainer,
    surfaceDim: Color = this.surfaceDim,
    surface: Color = this.surface,
    surfaceBright: Color = this.surfaceBright,
    onSurface: Color = this.onSurface,
    onSurfaceVariant: Color = this.onSurfaceVariant,
    outline: Color = this.outline,
    outlineVariant: Color = this.outlineVariant,
    background: Color = this.background,
    onBackground: Color = this.onBackground,
    error: Color = this.error,
    onError: Color = this.onError
): ColorScheme

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

toString

open fun toString(): String

Public properties

background

Added in 1.0.0-alpha21
val backgroundColor

The background color that appears behind other content.

error

Added in 1.0.0-alpha21
val errorColor

The error color is used to indicate errors.

onBackground

Added in 1.0.0-alpha21
val onBackgroundColor

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

onError

Added in 1.0.0-alpha21
val onErrorColor

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

onPrimary

Added in 1.0.0-alpha21
val onPrimaryColor

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

onPrimaryContainer

Added in 1.0.0-alpha21
val onPrimaryContainerColor

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

onSecondary

Added in 1.0.0-alpha21
val onSecondaryColor

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

onSecondaryContainer

Added in 1.0.0-alpha21
val onSecondaryContainerColor

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

onSurface

Added in 1.0.0-alpha21
val onSurfaceColor

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

onSurfaceVariant

Added in 1.0.0-alpha21
val onSurfaceVariantColor

The color for secondary text and icons on top of surface.

onTertiary

Added in 1.0.0-alpha21
val onTertiaryColor

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

onTertiaryContainer

Added in 1.0.0-alpha21
val onTertiaryContainerColor

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

outline

Added in 1.0.0-alpha21
val outlineColor

The main color for primary outline components. The outline color role adds contrast for accessibility purposes.

outlineVariant

Added in 1.0.0-alpha21
val outlineVariantColor

The secondary color for secondary outline components.

primary

Added in 1.0.0-alpha21
val primaryColor

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

primaryContainer

Added in 1.0.0-alpha21
val primaryContainerColor

is a standout container color for key components.

primaryDim

Added in 1.0.0-alpha21
val primaryDimColor

is less prominent than primary for component backgrounds

secondary

Added in 1.0.0-alpha21
val secondaryColor

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

secondaryContainer

Added in 1.0.0-alpha21
val secondaryContainerColor

A tonal color to be used in containers.

secondaryDim

Added in 1.0.0-alpha21
val secondaryDimColor

is less prominent than secondary for component backgrounds.

surface

Added in 1.0.0-alpha21
val surfaceColor

The main surface color that affect surfaces of components with large containment areas, such as Card and Button.

surfaceBright

Added in 1.0.0-alpha21
val surfaceBrightColor

A surface color used for large containment components such Card and Button with high prominence.

surfaceDim

Added in 1.0.0-alpha21
val surfaceDimColor

A surface color used for large containment components such as Card and Button with low prominence.

tertiary

Added in 1.0.0-alpha21
val tertiaryColor

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

tertiaryContainer

Added in 1.0.0-alpha21
val tertiaryContainerColor

A tonal color to be used in containers.

tertiaryDim

Added in 1.0.0-alpha21
val tertiaryDimColor

A less prominent tertiary color that can be used to balance primary and secondary colors, or bring heightened attention to an element.

Extension functions

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