在Jetpack中请求关注TextField撰写 [英] Request Focus on TextField in jetpack compose
本文介绍了在Jetpack中请求关注TextField撰写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在jetpack撰写中自动关注文本字段.当我单击文本字段并开始在其上键入时.同时,当我单击后退"按钮时,然后当我尝试单击文本字段时,什么也没有发生.
How to auto focus on textfield in jetpack compose. When i click on textfield and start typing on it. Meantime when i click back button,then when i'm try to click on textfield, nothing happens.
val textState = remember { mutableStateOf(TextFieldValue()) }
TextField(
modifier = Modifier.fillMaxWidth(),
value = textState.value,
onValueChange = { value : TextFieldValue ->
textState.value = value
}
)
推荐答案
发布问题的最新答案(API在Compose Beta中重命名)
Posting an updated Answer to the question (APIs were renamed in Compose Beta)
@Composable
fun AutoFocusingText() {
var value by mutableStateOf("Enter Text")
val focusRequester = remember { FocusRequester() }
TextField(
value = value,
onValueChange = { value = it },
modifier = Modifier.focusRequester(focusRequester)
)
DisposableEffect(Unit) {
focusRequester.requestFocus()
onDispose { }
}
}
这篇关于在Jetpack中请求关注TextField撰写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文