How can I set the cursor in a random position on a TextField when it it get focus? The equivalent of editText.setSelection(position) with the classic android view system.
This is the code I am using to have an edit text automatically receive the focus when it is added to the screen. I would like to be able to move the cursor from the default position which is 0
val (getText, setText) = remember { mutableStateOf("hello") } AutofocusEditText( text = getText, setText = setText ) ... @Composable private fun AutofocusEditText( text: String, setText : (String) -> Unit ) { val focusState = remember { mutableStateOf(FocusState.Inactive) } val focusRequester = FocusRequester() val focusModifier = Modifier.focus() Row( modifier = Modifier.focusObserver { newFocusValue -> focusState.value = newFocusValue } ) { val focusRequesterModifier = Modifier.focusRequester(focusRequester) TextField( value = text, modifier = focusModifier.then(focusRequesterModifier), backgroundColor = Color.Transparent, onValueChange = setText, keyboardOptions = KeyboardOptions.Default.copy( imeAction = ImeAction.Done ), onImeActionPerformed = { action, softKeyboardController -> if (action == ImeAction.Done) { softKeyboardController?.hideSoftwareKeyboard() } } ) } onActive { focusRequester.requestFocus() } }