BasticTextField2 隐藏后不再显示键盘

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

我正面临这个问题。使用新的

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
进行更改即可。我究竟做错了什么?谢谢你。

android kotlin android-jetpack-compose
1个回答
0
投票

我这边也有同样的问题。 我的解决方案是隐藏键盘时清除焦点。

© www.soinside.com 2019 - 2024. All rights reserved.