当我单击“下一步”ImeAction 时,光标位置会转到新选择的 TextField 的先前记住的位置(即,如果您曾经手动设置光标位置)。如果没有,那么即使 TextField 不为空,光标也会跳到开头。当通过 ImeAction 获得焦点时,我希望光标始终位于最后。
示例代码(为简单起见,我在这里持有可变状态,不使用 ViewModel):
@Composable
fun ImeActionIsBroken() {
val focusRequester = remember { FocusRequester() }
Column {
var value1 by rememberSaveable { mutableStateOf("Some value 1") }
TextField(
value = value1,
onValueChange = { value1 = it },
modifier = Modifier.fillMaxWidth(),
keyboardActions = KeyboardActions {
focusRequester.requestFocus()
},
singleLine = true
)
var value2 by rememberSaveable { mutableStateOf("Some value 2") }
TextField(
value = value2,
onValueChange = { value2 = it },
modifier = Modifier
.fillMaxWidth()
.focusRequester(focusRequester),
singleLine = true
)
}
}
撰写版本 1.0.5