Container
Container is a building block component that can be used for any static element or as an interactive container.
Since
0.3.1
Parameters
Modifier to be applied to the container layout for styling and positioning.
Background color of the container.
Color for content elements within the container.
Defines the shape of the container.
Optional border to apply around the container.
A Composable lambda that defines the content inside the container.
Container is a building block component that can be used for any selectable TV element or on its own as a selectable container. The Container handles an additional state compared to Container to indicate whether it is currently selected.
Parameters
Callback to be called when the container is clicked. If this and onLongClick are null, the container will not be focusable on TV.
Modifier to be applied to the layout corresponding to the container.
Whether or not the container is enabled.
Whether or not the container is currently selected.
Callback to be called when the container is long clicked. If this and onClick are null, the container will not be focusable on TV.
The Style to supply to the Container. See StyleDefaults.style.
An optional hoisted MutableInteractionSource for observing and emitting Interactions for this container.
Defines the Composable content inside the container.
Example:
Container(
style =
StyleDefaults.style(
colors = StyleDefaults.colors(
backgroundColor = Color.Black,
contentColor = Color.White,
focusedBackgroundColor = Color.Blue,
focusedContentColor = Color.Yellow,
pressedBackgroundColor = Color.Black.copy(alpha = 0.6f)
),
scale = StyleDefaults.scale(focusedScale = 1.1f),
shapes = StyleDefaults.shapes(RoundedCornerShape(8.dp))
),
modifier = Modifier.size(300.dp, 100.dp),
onClick = { /* Handle click */},
onLongClick = { /* Handle long click */}
) {
val color = LocalContentColor.current
BasicText(text = "Interactive Container", color = { color })
}
Example usage as a selectable container.
var selected by remember { mutableStateOf(false) }
Container(
onClick = {
selected = !selected
},
selected = selected,
style =
StyleDefaults.style(
colors = StyleDefaults.colors(
backgroundColor = if (selected) Color.Green else Color.Black,
contentColor = Color.White,
focusedBackgroundColor = Color.Red,
focusedContentColor = Color.Black,
pressedBackgroundColor = Color.Black.copy(alpha = 0.6f)
),
scale = StyleDefaults.scale(focusedScale = 1.1f),
shapes = StyleDefaults.shapes(RoundedCornerShape(8.dp))
)
) {
val color = LocalContentColor.current
BasicText(
text = if (selected) "Selected Container" else "Unselected Container",
color = { color },
)
}