Compose Modifier

background

Draws shape with a solid color behind the content.

DrawBackgroundColor

@Composable
@Sampled
fun DrawBackgroundColor() {
    Text("Text with background", Modifier.background(color = Color.Magenta).padding(10.dp))
}

DrawBackgroundShapedBrush

@Composable
@Sampled
fun DrawBackgroundShapedBrush() {
    val gradientBrush =
        Brush.horizontalGradient(
            colors = listOf(Color.Red, Color.Blue, Color.Green),
            startX = 0.0f,
            endX = 500.0f,
        )
    Text(
        "Text with gradient back",
        Modifier.background(brush = gradientBrush, shape = CutCornerShape(8.dp)).padding(10.dp),
    )
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: