gpt4 book ai didi

android - 导航到jetpack compose中的可组合项时如何自动请求焦点到文本字段

转载 作者:行者123 更新时间:2023-12-04 13:08:28 25 4
gpt4 key购买 nike

当用户导航到可组合项时,我希望键盘通过自动请求焦点在 jetpack compose 中的文本字段弹出。截至目前,这是我尝试过的,但似乎没有用

val feedbackContent = remember { mutableStateOf(TextFieldValue()) }
val focusRequester = remember { FocusRequester() }

OutlinedTextField(
modifier = Modifier
.clickable {
focusRequester.requestFocus()
}
.fillMaxWidth()
.focusRequester(focusRequester)
.focusable()
)

最佳答案

你可以使用类似的东西:

val focusRequester = FocusRequester()
val keyboardController = LocalSoftwareKeyboardController.current

OutlinedTextField(
value = text,
onValueChange = { text = it},
modifier = Modifier
.fillMaxWidth()
.focusRequester(focusRequester)
.onFocusChanged {
if (it.isFocused) {
keyboardController?.show()
}
}
)

DisposableEffect(Unit) {
focusRequester.requestFocus()
onDispose { }
}

关于android - 导航到jetpack compose中的可组合项时如何自动请求焦点到文本字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68268544/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com