Want to replicate this Edit Text feature Get Cursor Position in Android in Edit Text? in Android Jetpack Compose.
Asked
Active
Viewed 88 times
1 Answers
1
To get text field selection in compose, you need to use TextFieldValue
, like this:
var textFieldValue by remember { mutableStateOf(TextFieldValue(text = "")) }
TextField(
value = textFieldValue,
onValueChange = {
textFieldValue = it
},
)
Then you can get selection with textFieldValue.selection
, for example on key event with Modifier.onKeyEvent
, on button click, etc.

Phil Dukhov
- 67,741
- 15
- 184
- 220