You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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解决了问题:

  1. 在AndroidManifest.xml中设置android:windowSoftInputMode="adjustPan"
  2. 在LaunchedEffect(imeState.value)中添加如下代码:
WindowCompat.setDecorFitsSystemWindows(wnd, false)
wnd.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)

内容的提问来源于stack exchange,提问作者Robert

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 23:48:26