Jetpack Compose中AlertDialog内TextField被键盘遮挡问题求助
Jetpack Compose中AlertDialog内TextField被键盘遮挡的问题
在Jetpack Compose开发中,我遇到了一个问题:AlertDialog内部的TextField弹出软键盘时会被遮挡。我尝试了所有能找到的解决方案,但都没有效果,具体包括:
- 在AndroidManifest.xml的Activity中配置
android:windowSoftInputMode="adjustResize" - 在DialogProperties中设置
decorFitsSystemWindows = false - 为Dialog的Window调用
WindowCompat.setDecorFitsSystemWindows(window, false) - 在Activity的
onCreate()方法中调用WindowCompat.setDecorFitsSystemWindows(window, false) - 使用ImeState方案
- 使用BringIntoViewRequester:
modifier .onFocusEvent { if (it.isFocused) { coroutineScope.launch { delay(200) bringIntoViewRequester.bringIntoView() } } } .bringIntoViewRequester(bringIntoViewRequester)
我已创建演示项目用于复现该问题。
更新:问题已解决
基于@Shubham Thorat的思路,通过以下步骤使用adjustPan解决了问题:
- 在AndroidManifest.xml中设置
android:windowSoftInputMode="adjustPan" - 在
LaunchedEffect(imeState.value)中添加如下代码:
WindowCompat.setDecorFitsSystemWindows(wnd, false) wnd.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
内容的提问来源于stack exchange,提问作者Robert
相关产品推荐
相关产品推荐

