【问题标题】:How to prevent resizing and relayout the window when soft keyboard displaying软键盘显示时如何防止调整窗口大小和重新布局
【发布时间】:2012-07-12 07:13:22
【问题描述】:

我在一个活动中显示了一个编辑对话框,当软键盘显示时,活动的窗口将被调整为太小,看起来很糟糕。 I don't want the window of the activity be resized and layout. I just want the keyboard can cover on the activity window and the dialog move to the top so that soft keyboard have room to show.

我曾尝试在清单中使用 android:windowSoftInputMode="xxxxx",但没有一种模式适合我的情况。我也找到了类似的question,但是并没有解决我的问题。

编辑:我已经尝试过setImeOptionsgetWindown().setFlags,但仍然没有成功,任何建议都将不胜感激。

EDIT2:我在 3.0 中尝试过,并使用 android:windowSoftInputMode="adjustNothing",效果很好,但我如何在 2.3 上实现呢?

【问题讨论】:

    标签: android keyboard resize


    【解决方案1】:

    在 AndroidManifest.xml 中为您的 Activity 添加此属性:

    android:configChanges="orientation|keyboardHidden|screenSize"
    android:windowSoftInputMode="stateUnchanged|adjustPan"
    

    【讨论】:

    • 添加 android:configChanges 语句而不确切知道它们做了什么不是一个好主意。 “方向”部分既与问题无关,也不鼓励。
    【解决方案2】:

    我找到了避免问题的方法,但是只是避免,还是想知道android 2.3中的解决方法。

    之前,我在XML中从上到下布局控件,就像这样:

    <ToolBar android:id="@+id/blabla"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true" />
    

    所以当键盘显示的时候,activity的窗口被resize了,所以ToolBar被推了,看起来不太好。

    现在,我从顶部开始布局控件,通过窗口仍然调整大小,但工具栏和其他控件不会被推送,它们只是在窗口外布局,当软键盘显示时。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-09
      • 2016-06-16
      • 2021-02-19
      • 1970-01-01
      • 2021-12-16
      • 2019-03-05
      • 1970-01-01
      相关资源
      最近更新 更多