按 BasicTextField 的 imeAction 后,不会调用 onKeyboardAction

问题描述 投票:0回答:1

BasicTextField
和 jetpack 中的
TextFieldState
中,按下键盘上的完成按钮时不会调用键盘操作,以下是我的代码:

    BasicTextField(
        modifier = Modifier,
        textStyle = TextStyle(
            textAlign = TextAlign.End,
            fontSize = 16.sp,
            color = Color.DarkGray
        ),
        inputTransformation = InputTransformation.maxLength(3),
        enabled = true,
        state = rememberTextFieldState(),
        keyboardOptions = KeyboardOptions(
            imeAction = ImeAction.Done,
            keyboardType = KeyboardType.Number
        ),
        lineLimits = TextFieldLineLimits.SingleLine,
        onKeyboardAction = {
            KeyboardActions(
                onDone = {
                    Log.d("bbbrand", "onDone")
                    keyboard?.hide()
                }
            )
        }
android kotlin android-jetpack-compose
1个回答
0
投票

在新的

BasicTextField
中,
onKeyboardAction
应该直接实现,以下是工作代码:

BasicTextField(
    modifier = Modifier,
    textStyle = TextStyle(
        textAlign = TextAlign.End,
        fontSize = 16.sp,
        color = Color.DarkGray
    ),
    inputTransformation = InputTransformation.maxLength(3),
    enabled = true,
    state = rememberTextFieldState(),
    keyboardOptions = KeyboardOptions(
        imeAction = ImeAction.Done,
        keyboardType = KeyboardType.Number
    ),
    lineLimits = TextFieldLineLimits.SingleLine,
    onKeyboardAction = {
          Log.d("bbbrand", "onDone")
          keyboard?.hide()
    }
© www.soinside.com 2019 - 2024. All rights reserved.