谁能告诉我如何禁用和启用Enter软键盘中的键?
我想覆盖ENTER虚拟键盘的键的行为,以便:
我一直在玩IME选项和标签,但只是没有得到我想要的.有人有什么建议吗?
我有这个 TextFied 可组合项,同时包含KeyboardOptions和KeyboardActions。
@Composable
fun TodoInputText(...) {
val keyboardController = LocalSoftwareKeyboardController.current
TextField( ....
onValueChange = onTextChanged,
keyboardOptions = KeyboardOptions.Default.copy(imeAction = ImeAction.Done),
keyboardActions = KeyboardActions(onDone = {
onImeAction()
keyboardController?.hide()
}))}
Run Code Online (Sandbox Code Playgroud)
TextField 正在与 Done Action 配合使用,但只要 TextFied 为空,我就需要在键盘上禁用 Done ImeAction,如此 GIF 所示
我已经提取了一个状态来检查 TextField 是否为空。
@Composable
fun TodoItemEntryInput(...) {
//hold state for TextField
val (text, setText) = remember { mutableStateOf("") }
val isTextBlank = text.isNotBlank()
//declare lambda function submit that handles a submit event when done is pressed …Run Code Online (Sandbox Code Playgroud)