'Surface at +(...)% colors in jetpack compose

In official Material Design 3 resources (e.g. the Figma design kit), there have been many references to colors called "Surface at +x". These colors are the surface color mixed with x% of the primary color.

Now my question:

How can you implement the "Surface at +x" colors in Jetpack Compose? There is no documentation and no property on the MaterialTheme.colorScheme object.

Figma Design Kit reference: Colors in the Figma Material Design 3 UI Kit



Solution 1:[1]

Surface uses MaterialTheme.colorScheme.surface by default, they also have a new tonalElevation property which you can read about here.

The gist of it is that increasing the tonal elevation changes the color automatically, try it yourself:

Surface(tonalElevation = 5.dp) {
    // content
}

Solution 2:[2]

In case anyone need to get it in a non-compose code, use SurfaceColors enums:

int colorSurface1 = SurfaceColors.SURFACE_2.getColor(context);

Documentation can be found here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Scott Cooper
Solution 2 Dannie