{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

ColorSchemeKt

public final class ColorSchemeKt


Summary

Public methods

static final @NonNull Color

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

static final @NonNull Color
contentColorFor(
    @NonNull ColorScheme receiver,
    @NonNull Color backgroundColor
)

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

static final @NonNull ColorScheme
darkColorScheme(
    @NonNull Color primary,
    @NonNull Color onPrimary,
    @NonNull Color primaryContainer,
    @NonNull Color onPrimaryContainer,
    @NonNull Color inversePrimary,
    @NonNull Color secondary,
    @NonNull Color onSecondary,
    @NonNull Color secondaryContainer,
    @NonNull Color onSecondaryContainer,
    @NonNull Color tertiary,
    @NonNull Color onTertiary,
    @NonNull Color tertiaryContainer,
    @NonNull Color onTertiaryContainer,
    @NonNull Color background,
    @NonNull Color onBackground,
    @NonNull Color surface,
    @NonNull Color onSurface,
    @NonNull Color surfaceVariant,
    @NonNull Color onSurfaceVariant,
    @NonNull Color surfaceTint,
    @NonNull Color inverseSurface,
    @NonNull Color inverseOnSurface,
    @NonNull Color error,
    @NonNull Color onError,
    @NonNull Color errorContainer,
    @NonNull Color onErrorContainer,
    @NonNull Color outline,
    @NonNull Color outlineVariant,
    @NonNull Color scrim,
    @NonNull Color surfaceBright,
    @NonNull Color surfaceContainer,
    @NonNull Color surfaceContainerHigh,
    @NonNull Color surfaceContainerHighest,
    @NonNull Color surfaceContainerLow,
    @NonNull Color surfaceContainerLowest,
    @NonNull Color surfaceDim
)

Returns a dark Material color scheme.

static final @NonNull ProvidableCompositionLocal<@NonNull Boolean>

Composition Local used to check if ColorScheme.applyTonalElevation will be applied down the tree.

static final @NonNull ColorScheme
lightColorScheme(
    @NonNull Color primary,
    @NonNull Color onPrimary,
    @NonNull Color primaryContainer,
    @NonNull Color onPrimaryContainer,
    @NonNull Color inversePrimary,
    @NonNull Color secondary,
    @NonNull Color onSecondary,
    @NonNull Color secondaryContainer,
    @NonNull Color onSecondaryContainer,
    @NonNull Color tertiary,
    @NonNull Color onTertiary,
    @NonNull Color tertiaryContainer,
    @NonNull Color onTertiaryContainer,
    @NonNull Color background,
    @NonNull Color onBackground,
    @NonNull Color surface,
    @NonNull Color onSurface,
    @NonNull Color surfaceVariant,
    @NonNull Color onSurfaceVariant,
    @NonNull Color surfaceTint,
    @NonNull Color inverseSurface,
    @NonNull Color inverseOnSurface,
    @NonNull Color error,
    @NonNull Color onError,
    @NonNull Color errorContainer,
    @NonNull Color onErrorContainer,
    @NonNull Color outline,
    @NonNull Color outlineVariant,
    @NonNull Color scrim,
    @NonNull Color surfaceBright,
    @NonNull Color surfaceContainer,
    @NonNull Color surfaceContainerHigh,
    @NonNull Color surfaceContainerHighest,
    @NonNull Color surfaceContainerLow,
    @NonNull Color surfaceContainerLowest,
    @NonNull Color surfaceDim
)

Returns a light Material color scheme.

static final @NonNull Color
surfaceColorAtElevation(
    @NonNull ColorScheme receiver,
    @NonNull Dp elevation
)

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

Public methods

contentColorFor

@Composable
public static final @NonNull Color contentColorFor(@NonNull Color backgroundColor)

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 the current value of LocalContentColor as a best-effort color.

Returns
@NonNull Color

the matching content color for backgroundColor. If backgroundColor is not present in the theme's ColorScheme, then returns the current value of LocalContentColor.

See also
contentColorFor

contentColorFor

public static final @NonNull Color contentColorFor(
    @NonNull ColorScheme receiver,
    @NonNull Color backgroundColor
)

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
@NonNull Color

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

See also
contentColorFor

darkColorScheme

public static final @NonNull ColorScheme darkColorScheme(
    @NonNull Color primary,
    @NonNull Color onPrimary,
    @NonNull Color primaryContainer,
    @NonNull Color onPrimaryContainer,
    @NonNull Color inversePrimary,
    @NonNull Color secondary,
    @NonNull Color onSecondary,
    @NonNull Color secondaryContainer,
    @NonNull Color onSecondaryContainer,
    @NonNull Color tertiary,
    @NonNull Color onTertiary,
    @NonNull Color tertiaryContainer,
    @NonNull Color onTertiaryContainer,
    @NonNull Color background,
    @NonNull Color onBackground,
    @NonNull Color surface,
    @NonNull Color onSurface,
    @NonNull Color surfaceVariant,
    @NonNull Color onSurfaceVariant,
    @NonNull Color surfaceTint,
    @NonNull Color inverseSurface,
    @NonNull Color inverseOnSurface,
    @NonNull Color error,
    @NonNull Color onError,
    @NonNull Color errorContainer,
    @NonNull Color onErrorContainer,
    @NonNull Color outline,
    @NonNull Color outlineVariant,
    @NonNull Color scrim,
    @NonNull Color surfaceBright,
    @NonNull Color surfaceContainer,
    @NonNull Color surfaceContainerHigh,
    @NonNull Color surfaceContainerHighest,
    @NonNull Color surfaceContainerLow,
    @NonNull Color surfaceContainerLowest,
    @NonNull Color surfaceDim
)

Returns a dark Material color scheme.

getLocalTonalElevationEnabled

public static final @NonNull ProvidableCompositionLocal<@NonNull BooleangetLocalTonalElevationEnabled()

Composition Local used to check if ColorScheme.applyTonalElevation will be applied down the tree.

Setting this value to false will cause all subsequent surfaces down the tree to not apply tonalElevation.

lightColorScheme

public static final @NonNull ColorScheme lightColorScheme(
    @NonNull Color primary,
    @NonNull Color onPrimary,
    @NonNull Color primaryContainer,
    @NonNull Color onPrimaryContainer,
    @NonNull Color inversePrimary,
    @NonNull Color secondary,
    @NonNull Color onSecondary,
    @NonNull Color secondaryContainer,
    @NonNull Color onSecondaryContainer,
    @NonNull Color tertiary,
    @NonNull Color onTertiary,
    @NonNull Color tertiaryContainer,
    @NonNull Color onTertiaryContainer,
    @NonNull Color background,
    @NonNull Color onBackground,
    @NonNull Color surface,
    @NonNull Color onSurface,
    @NonNull Color surfaceVariant,
    @NonNull Color onSurfaceVariant,
    @NonNull Color surfaceTint,
    @NonNull Color inverseSurface,
    @NonNull Color inverseOnSurface,
    @NonNull Color error,
    @NonNull Color onError,
    @NonNull Color errorContainer,
    @NonNull Color onErrorContainer,
    @NonNull Color outline,
    @NonNull Color outlineVariant,
    @NonNull Color scrim,
    @NonNull Color surfaceBright,
    @NonNull Color surfaceContainer,
    @NonNull Color surfaceContainerHigh,
    @NonNull Color surfaceContainerHighest,
    @NonNull Color surfaceContainerLow,
    @NonNull Color surfaceContainerLowest,
    @NonNull Color surfaceDim
)

Returns a light Material color scheme.

surfaceColorAtElevation

public static final @NonNull Color surfaceColorAtElevation(
    @NonNull ColorScheme receiver,
    @NonNull Dp elevation
)

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

Parameters
@NonNull Dp elevation

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

Returns
@NonNull Color

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