androidx.compose.foundation.text.selection
SelectionContainer
Composable function · from org.jetbrains.compose.foundation:foundation:1.12.2
Text in Compose can't be selected by default. Wrap it in a SelectionContainer to let the user select and copy it.
SelectionContainer {
Column {
Text("Order number")
Text("A-1042-7731")
}
}
The selection can go across several Texts inside the container. To keep a part from being selected, wrap it in DisableSelection.
Basic
Selection handled for you.
@Composable
fun SelectionContainer(
modifier: Modifier = Modifier,
content: @Composable () -> Unit,
)
modifier: ModifierOptional
modifier: ModifierOptionalDefault: Modifier
Changes size, padding, or position. See the Modifier guide.
content: @Composable () -> UnitRequired
content: @Composable () -> UnitRequiredThe text that can be selected.
With a stateSince 1.12
You can read or clear the selection.
@Composable
fun SelectionContainer(
state: SelectionState,
modifier: Modifier = Modifier,
content: @Composable () -> Unit,
)
state: SelectionStateRequired
state: SelectionStateRequiredHolds the current selection, so you can read or clear it.
Same as above: modifier, content.
Selection
SelectionContainerDisableSelection