Class

SelectionState

Selection state object for a particular SelectionContainer.

SelectionStateSample

@Sampled
@Composable
fun SelectionStateSample() {
    val selectionState = rememberSelectionState()

    val characterCount = selectionState.selectedTexts.sumOf { it.text.length }

    Column {
        SelectionContainer(state = selectionState) {
            Column { BasicText(text = "Text to be selected...") }
        }
        if (characterCount > 0) {
            BasicText(text = "Characters selected: $characterCount")
        }
    }
}
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: