在
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()
}
)
}
在新的
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()
}