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

ShadowKt

public final class ShadowKt


Summary

Public methods

static final @NonNull Modifier
shadow(
    @NonNull Modifier receiver,
    @NonNull Dp elevation,
    @NonNull Shape shape,
    boolean clip,
    @NonNull Color ambientColor,
    @NonNull Color spotColor
)

Creates a graphicsLayer that draws a shadow.

Public methods

shadow

public static final @NonNull Modifier shadow(
    @NonNull Modifier receiver,
    @NonNull Dp elevation,
    @NonNull Shape shape,
    boolean clip,
    @NonNull Color ambientColor,
    @NonNull Color spotColor
)

Creates a graphicsLayer that draws a shadow. The elevation defines the visual depth of the physical object. The physical object has a shape specified by shape.

If the passed shape is concave the shadow will not be drawn on Android versions less than 10.

Note that elevation is only affecting the shadow size and doesn't change the drawing order. Use a androidx.compose.ui.zIndex modifier if you want to draw the elements with larger elevation after all the elements with a smaller one.

Usage of this API renders this composable into a separate graphics layer

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.unit.dp

Box(
    Modifier.shadow(12.dp, RectangleShape)
        .size(100.dp, 100.dp)
)
Parameters
@NonNull Dp elevation

The elevation for the shadow in pixels

@NonNull Shape shape

Defines a shape of the physical object

boolean clip

When active, the content drawing clips to the shape.

See also
graphicsLayer

Example usage: