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,
    surfaceContainerLow: Color,
    surfaceContainer: Color,
    surfaceContainerHigh: Color,
    onSurface: Color,
    onSurfaceVariant: Color,
    outline: Color,
    outlineVariant: Color,
    background: Color,
    onBackground: Color,
    error: Color,
    onError: Color,
    errorContainer: Color,
    onErrorContainer: 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,
    surfaceContainerLow: Color,
    surfaceContainer: Color,
    surfaceContainerHigh: Color,
    onSurface: Color,
    onSurfaceVariant: Color,
    outline: Color,
    outlineVariant: Color,
    background: Color,
    onBackground: Color,
    error: Color,
    onError: Color,
    errorContainer: Color,
    onErrorContainer: 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

Color that indicates remove, delete, close or dismiss actions, such as Swipe to Reveal.

Color

Color that indicates errors or emergency actions, such as safety alerts.

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 on the errorContainer 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 surfaceContainer.

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,
    surfaceContainerLow: Color = ColorTokens.SurfaceContainerLow,
    surfaceContainer: Color = ColorTokens.SurfaceContainer,
    surfaceContainerHigh: Color = ColorTokens.SurfaceContainerHigh,
    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,
    errorContainer: Color = ColorTokens.ErrorContainer,
    onErrorContainer: Color = ColorTokens.OnErrorContainer
)

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,
    surfaceContainerLow: Color = this.surfaceContainerLow,
    surfaceContainer: Color = this.surfaceContainer,
    surfaceContainerHigh: Color = this.surfaceContainerHigh,
    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,
    errorContainer: Color = this.errorContainer,
    onErrorContainer: Color = this.onErrorContainer
): 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-alpha30
val backgroundColor

The background color that appears behind other content.

error

Added in 1.0.0-alpha30
val errorColor

Color that indicates remove, delete, close or dismiss actions, such as Swipe to Reveal. Added as an errorContainer alternative that is slightly less alarming and urgent color.

errorContainer

Added in 1.0.0-alpha30
val errorContainerColor

Color that indicates errors or emergency actions, such as safety alerts. This color is for use-cases that are more alarming and urgent than the error color.

onBackground

Added in 1.0.0-alpha30
val onBackgroundColor

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

onError

Added in 1.0.0-alpha30
val onErrorColor

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

onErrorContainer

Added in 1.0.0-alpha30
val onErrorContainerColor

Color used for text and icons on the errorContainer color.

onPrimary

Added in 1.0.0-alpha30
val onPrimaryColor

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

onPrimaryContainer

Added in 1.0.0-alpha30
val onPrimaryContainerColor

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

onSecondary

Added in 1.0.0-alpha30
val onSecondaryColor

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

onSecondaryContainer

Added in 1.0.0-alpha30
val onSecondaryContainerColor

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

onSurface

Added in 1.0.0-alpha30
val onSurfaceColor

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

onSurfaceVariant

Added in 1.0.0-alpha30
val onSurfaceVariantColor

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

onTertiary

Added in 1.0.0-alpha30
val onTertiaryColor

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

onTertiaryContainer

Added in 1.0.0-alpha30
val onTertiaryContainerColor

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

outline

Added in 1.0.0-alpha30
val outlineColor

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

outlineVariant

Added in 1.0.0-alpha30
val outlineVariantColor

The secondary color for secondary outline components.

primary

Added in 1.0.0-alpha30
val primaryColor

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

primaryContainer

Added in 1.0.0-alpha30
val primaryContainerColor

is a standout container color for key components.

primaryDim

Added in 1.0.0-alpha30
val primaryDimColor

is less prominent than primary for component backgrounds

secondary

Added in 1.0.0-alpha30
val secondaryColor

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

secondaryContainer

Added in 1.0.0-alpha30
val secondaryContainerColor

A tonal color to be used in containers.

secondaryDim

Added in 1.0.0-alpha30
val secondaryDimColor

is less prominent than secondary for component backgrounds.

surfaceContainer

Added in 1.0.0-alpha30
val surfaceContainerColor

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

surfaceContainerHigh

Added in 1.0.0-alpha30
val surfaceContainerHighColor

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

surfaceContainerLow

Added in 1.0.0-alpha30
val surfaceContainerLowColor

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

tertiary

Added in 1.0.0-alpha30
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-alpha30
val tertiaryContainerColor

A tonal color to be used in containers.

tertiaryDim

Added in 1.0.0-alpha30
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