Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetpack Compose - SelectionContainer - how to add missing functionality?

I'm trying to replicate some View-based selected text behavior with Jetpack Compose. In both of these cases, I've long-tapped on the middle of the URL.

View based:

<TextView ... android:textIsSelectable="true" />

view-based-screenshot

Compose:

    SelectionContainer {
        Text(...)
    }

compose-based-screenshot

As you can see in the screenshots, there are a few missing options in the Compose layout. Is there a way to add this? Yes, I know I can use AndroidView but is there a more composey way to do it? Here's what's in the View layout, but lacking from the Compose layout:

  • "Share"
  • "Select All"
  • "Open" when a url is selected
  • (AI-based?) auto selection of URLs. Tap and hold anywhere on the URL automatically selects the URL part.

Edit: I'm not asking for a custom toolbar, I'm asking for the one Google provides in TextView.

like image 958
dgmltn Avatar asked Dec 05 '25 03:12

dgmltn


1 Answers

While this is still not supported, if you use a TextField instead of a Text you at least get the "Select all" option too.

@Composable
private fun SelectableTextField() {
    TextField(
        value = "This is a selectable text",
        onValueChange = {},
        keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
        readOnly = true,
        colors = TextFieldDefaults.colors(
            focusedContainerColor = Color.Transparent,
            unfocusedContainerColor = Color.Transparent,
            focusedIndicatorColor = Color.Transparent,
            unfocusedIndicatorColor = Color.Transparent
        )
    )
}
like image 151
Eliza Camber Avatar answered Dec 08 '25 01:12

Eliza Camber



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!