← Back to Material Compose
Surface
Overview
Code Examples
<a href="https://material.io/design/environment/surfaces.html" class="external" target="_blank">Material Design surface</a>.
Material surface is the central metaphor in material design. Each surface exists at a given elevation, which influences how that piece of surface visually relates to other surfaces and how that surface casts shadows.
See the other overloads for clickable, selectable, and toggleable surfaces.
The Surface is responsible for:
Clipping: Surface clips its children to the shape specified by shape
Elevation: Surface draws a shadow to represent depth, where elevation represents the depth of this surface. If the passed shape is concave the shadow will not be drawn on Android versions less than 10.
Borders: If shape has a border, then it will also be drawn.
Background: Surface fills the shape specified by shape with the color. If color is Colors.surface, the ElevationOverlay from LocalElevationOverlay will be used to apply an overlay - by default this will only occur in dark theme. The color of the overlay depends on the elevation of this Surface, and the LocalAbsoluteElevation set by any parent surfaces. This ensures that a Surface never appears to have a lower elevation overlay than its ancestors, by summing the elevation of all previous Surfaces.
Content color: Surface uses contentColor to specify a preferred color for the content of this surface - this is used by the Text and Icon components as a default color.
Blocking touch propagation behind the surface.
If no contentColor is set, this surface will try and match its background color to a color defined in the theme Colors, and return the corresponding content color. For example, if the color of this surface is Colors.surface, contentColor will be set to Colors.onSurface. If color is not part of the theme palette, contentColor will keep the same value set above this Surface.
Overloads
Surface
@Composable
fun Surface(
modifier: Modifier = Modifier,
shape: Shape = RectangleShape,
color: Color = MaterialTheme.colors.surface,
contentColor: Color = contentColorFor(color),
border: BorderStroke? = null,
elevation: Dp = 0.dp,
content: @Composable () -> Unit
)
Parameters
Name | Description |
---|---|
modifier | Modifier to be applied to the layout corresponding to the surface |
shape | Defines the surface's shape as well its shadow. A shadow is only displayed if the elevation is greater than zero. |
color | The background color. Use Color.Transparent to have no color. |
contentColor | The preferred content color provided by this Surface to its children. Defaults to either the matching content color for color, or if color is not a color from the theme, this will keep the same value set above this Surface. |
border | Optional border to draw on top of the surface |
elevation | The size of the shadow below the surface. Note that It will not affect z index of the Surface. If you want to change the drawing order you can use Modifier.zIndex |
Surface
@ExperimentalMaterialApi
@Composable
fun Surface(
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
shape: Shape = RectangleShape,
color: Color = MaterialTheme.colors.surface,
contentColor: Color = contentColorFor(color),
border: BorderStroke? = null,
elevation: Dp = 0.dp,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
content: @Composable () -> Unit
)
Parameters
Name | Description |
---|---|
onClick | callback to be called when the surface is clicked |
modifier | Modifier to be applied to the layout corresponding to the surface |
enabled | Controls the enabled state of the surface. When false , this surface will not be clickable |
shape | Defines the surface's shape as well its shadow. A shadow is only displayed if the elevation is greater than zero. |
color | The background color. Use Color.Transparent to have no color. |
contentColor | The preferred content color provided by this Surface to its children. Defaults to either the matching content color for color, or if color is not a color from the theme, this will keep the same value set above this Surface. |
border | Optional border to draw on top of the surface |
elevation | The size of the shadow below the surface. Note that It will not affect z index of the Surface. If you want to change the drawing order you can use Modifier.zIndex . |
interactionSource | the MutableInteractionSource representing the stream of Interactions for this Surface. You can create and pass in your own remembered MutableInteractionSource if you want to observe Interactions and customize the appearance / behavior of this Surface in different Interactions |
Surface
@ExperimentalMaterialApi
@Composable
fun Surface(
selected: Boolean,
onClick: () -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
shape: Shape = RectangleShape,
color: Color = MaterialTheme.colors.surface,
contentColor: Color = contentColorFor(color),
border: BorderStroke? = null,
elevation: Dp = 0.dp,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
content: @Composable () -> Unit
)
Parameters
Name | Description |
---|---|
selected | whether this Surface is selected |
onClick | callback to be called when the surface is clicked |
modifier | Modifier to be applied to the layout corresponding to the surface |
enabled | Controls the enabled state of the surface. When false , this surface will not be selectable |
shape | Defines the surface's shape as well its shadow. A shadow is only displayed if the elevation is greater than zero. |
color | The background color. Use Color.Transparent to have no color. |
contentColor | The preferred content color provided by this Surface to its children. Defaults to either the matching content color for color, or if color is not a color from the theme, this will keep the same value set above this Surface. |
border | Optional border to draw on top of the surface |
elevation | The size of the shadow below the surface. Note that It will not affect z index of the Surface. If you want to change the drawing order you can use Modifier.zIndex . |
interactionSource | the MutableInteractionSource representing the stream of Interactions for this Surface. You can create and pass in your own remembered MutableInteractionSource if you want to observe Interactions and customize the appearance / behavior of this Surface in different Interactions |
Surface
@ExperimentalMaterialApi
@Composable
fun Surface(
checked: Boolean,
onCheckedChange: (Boolean) -> Unit,
modifier: Modifier = Modifier,
enabled: Boolean = true,
shape: Shape = RectangleShape,
color: Color = MaterialTheme.colors.surface,
contentColor: Color = contentColorFor(color),
border: BorderStroke? = null,
elevation: Dp = 0.dp,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
content: @Composable () -> Unit
)
Parameters
Name | Description |
---|---|
checked | whether or not this Surface is toggled on or off |
onCheckedChange | callback to be invoked when the toggleable Surface is clicked |
modifier | Modifier to be applied to the layout corresponding to the surface |
enabled | Controls the enabled state of the surface. When false , this surface will not be selectable |
shape | Defines the surface's shape as well its shadow. A shadow is only displayed if the elevation is greater than zero. |
color | The background color. Use Color.Transparent to have no color. |
contentColor | The preferred content color provided by this Surface to its children. Defaults to either the matching content color for color, or if color is not a color from the theme, this will keep the same value set above this Surface. |
border | Optional border to draw on top of the surface |
elevation | The size of the shadow below the surface. Note that It will not affect z index of the Surface. If you want to change the drawing order you can use Modifier.zIndex . |
interactionSource | the MutableInteractionSource representing the stream of Interactions for this Surface. You can create and pass in your own remembered MutableInteractionSource if you want to observe Interactions and customize the appearance / behavior of this Surface in different Interactions |