我正在使用 Jetpack Compose TextField
并且我想在用户按下操作按钮( imeActionPerformed
参数)时关闭虚拟键盘。
val text = +state { "" }
TextField(
value = text.value,
keyboardType = KeyboardType.Text,
imeAction = ImeAction.Done,
onImeActionPerformed = {
// TODO Close the virtual keyboard here <<<
}
onValueChange = { s -> text.value = s }
)
原文由 nglauber 发布,翻译遵循 CC BY-SA 4.0 许可协议
Starting from compose
1.0.0-alpha12
(and still valid in compose1.3.1
) theonImeActionPerformed
is deprecated and suggested approach is to usekeyboardActions
with combination ofkeyboardOptions
:focusManager.clearFocus()
将负责关闭软键盘。