如何在导航到可组合的jetpack组合时自动请求焦点到文本字段



当用户导航到可组合文件时,我希望通过自动请求将焦点放在jetpack compose中的文本字段上来弹出键盘。到目前为止,这是我尝试过的,但似乎不起作用

val feedbackContent = remember { mutableStateOf(TextFieldValue()) }
val focusRequester = remember { FocusRequester() }
OutlinedTextField(
modifier = Modifier
.clickable {
focusRequester.requestFocus()
}
.fillMaxWidth()
.focusRequester(focusRequester)
.focusable()
)

您可以使用以下内容

val focusRequester = remember { FocusRequester() }
val keyboardController = LocalSoftwareKeyboardController.current
OutlinedTextField(
value = text,
onValueChange = { text = it},
modifier = Modifier
.fillMaxWidth()
.focusRequester(focusRequester)
.onFocusChanged {
if (it.isFocused) {
keyboardController?.show()
}
}
)
LaunchedEffect(Unit) {
focusRequester.requestFocus()
}

相关内容

  • 没有找到相关文章

最新更新