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( |
Public functions |
|
|---|---|
ColorScheme |
copy(Returns a copy of this ColorScheme, optionally overriding some of the values. |
open String |
toString() |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
Color |
Another option for a color with similar uses of |
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 |
ColorScheme.surfaceColorAtElevation(elevation: Dp)Computes the surface tonal color at different elevation levels e.g. surface1 through surface5. |
Public constructors
ColorScheme
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
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.
Public properties
background
val background: Color
The background color that appears behind scrollable content.
border
val border: Color
Subtle color used for boundaries. Border color role adds contrast for accessibility purposes.
borderVariant
val borderVariant: Color
Utility color used for boundaries for decorative elements when strong contrast is not required.
error
val error: Color
The error color is used to indicate errors in components, such as invalid text in a text field.
errorContainer
val errorContainer: Color
The preferred tonal color of error containers.
inverseOnSurface
val inverseOnSurface: Color
A color that contrasts well with inverseSurface. Useful for content that sits on top of containers that are inverseSurface.
inversePrimary
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
val inverseSurface: Color
A color that contrasts sharply with surface. Useful for surfaces that sit on top of other surfaces with surface color.
onBackground
val onBackground: Color
Color used for text and icons displayed on top of the background color.
onError
val onError: Color
Color used for text and icons displayed on top of the error color.
onErrorContainer
val onErrorContainer: Color
The color (and state variants) that should be used for content on top of errorContainer.
onPrimary
val onPrimary: Color
Color used for text and icons displayed on top of the primary color.
onPrimaryContainer
val onPrimaryContainer: Color
The color (and state variants) that should be used for content on top of primaryContainer.
onSecondary
val onSecondary: Color
Color used for text and icons displayed on top of the secondary color.
onSecondaryContainer
val onSecondaryContainer: Color
The color (and state variants) that should be used for content on top of secondaryContainer.
onSurface
val onSurface: Color
Color used for text and icons displayed on top of the surface color.
onSurfaceVariant
val onSurfaceVariant: Color
The color (and state variants) that can be used for content on top of surface.
onTertiary
val onTertiary: Color
Color used for text and icons displayed on top of the tertiary color.
onTertiaryContainer
val onTertiaryContainer: Color
The color (and state variants) that should be used for content on top of tertiaryContainer.
primary
val primary: Color
The primary color is the color displayed most frequently across your app’s screens and components.
primaryContainer
val primaryContainer: Color
The preferred tonal color of containers.
secondary
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
val secondaryContainer: Color
A tonal color to be used in containers.
surface
val surface: Color
The surface color that affect surfaces of components, such as cards, sheets, and menus.
surfaceTint
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
val surfaceVariant: Color
Another option for a color with similar uses of surface.
tertiary
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
val tertiaryContainer: Color
A tonal color to be used in containers.
Extension functions
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 |
| See also | |
|---|---|
contentColorFor |
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 |