{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}
public final class BackgroundKt
public static final @NonNull Modifier background(
@NonNull Modifier receiver,
@NonNull Color color,
@NonNull Shape shape
)
Draws shape
with a solid color
behind the content.
import androidx.compose.foundation.background import androidx.compose.foundation.layout.padding import androidx.compose.material.Text import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp Text( "Text with background", Modifier.background(color = Color.Magenta).padding(10.dp) )
public static final @NonNull Modifier background(
@NonNull Modifier receiver,
@NonNull Brush brush,
@NonNull Shape shape,
float alpha
)
Draws shape
with brush
behind the content.
import androidx.compose.foundation.background import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.CutCornerShape import androidx.compose.material.Text import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp 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) )