我正面临这个问题。使用新的
BasicTextField2
API,使用 Android 导航栏的后退键隐藏键盘并尝试按 BasicTextField2
再次显示键盘后,键盘不再显示。我打算通过以编程方式显示键盘来解决此问题,但似乎 BasicTextField2
无法检测按下的事件。
// Compose
var value by remember {
mutableStateOf("")
}
val interactionSource = remember {
MutableInteractionSource()
}
val pressed by interactionSource.collectIsPressedAsState()
val focused by interactionSource.collectIsFocusedAsState()
Log.d("CustomTextFieldEvents", "----------------------------")
Log.d("CustomTextFieldEvents: ", "Pressed: $pressed")
Log.d("CustomTextFieldEvents: ", "Focused: $focused")
Log.d("CustomTextFieldEvents", "----------------------------")
BasicTextField2(
modifier = modifier,
value = value,
onValueChange = { newValue ->
value = newValue
},
interactionSource = interactionSource
)
我只有在点击它时才能进入 logcat:
CustomTextFieldEvents com.marmatsan.app D ----------------------------
CustomTextFieldEvents: com.marmatsan.app D Pressed: false
CustomTextFieldEvents: com.marmatsan.app D Focused: true
CustomTextFieldEvents com.marmatsan.app D ----------------------------
用旧的
BasicTextField
进行更改即可。我究竟做错了什么?谢谢你。
我这边也有同样的问题。 我的解决方案是隐藏键盘时清除焦点。