【问题标题】:How to use "adjustPan" and "adjustResize" together如何一起使用“adjustPan”和“adjustResize”
【发布时间】:2015-03-27 00:29:45
【问题描述】:

我正面临一个奇怪的问题。我在一个活动中有两个片段。一个是登录 Fragment 。我在这个片段中有两个编辑文本。此文件中的某些设备被软键盘隐藏,我在清单中指定了adjustPan,这工作正常

当用户单击 LoginFragment 上的按钮时,我正在打开另一个名为 forgetpassword 的片段。这是一个 webview,url 正在从远程服务器加载。但是 html 中的文本字段被软键盘隐藏。所以我尝试使用adjustResize,它工作正常。但是我在 loginfragment 中的 editText 小部件被键盘隐藏了。

如何在我的活动中实现这两个标志。 请帮我解决这个问题。

【问题讨论】:

  • 嘿,您找到解决方案了吗?我也面临同样的问题。

标签: android window-soft-input-mode


【解决方案1】:

您可以通过以编程方式设置adjustPanadjustResize 来解决您的问题。

当当前Fragment是你的LoginFragment时,使用下面的代码设置ajustPan

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

当当前Fragment是你的webview Fragment时,使用下面的代码设置ajustResize

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

【讨论】:

  • 在清单中放置调整平移时,这可以正常工作,但是当尝试将这两个标志放置在带有这样标志的片段中时 getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager. LayoutParams.SOFT_INPUT_ADJUST_PAN);它没有。
  • @DougRay 他们不应该合并在一起,见developer.android.com/reference/android/view/…
【解决方案2】:

您可以通过以编程方式设置adjustPanadjustResize 来解决您的问题。 另外,在listview 中添加android:transcriptMode="alwaysScroll"

【讨论】:

    【解决方案3】:

    adjustResizeadjustPan不能相互组合。它们是防止软输入覆盖输入字段的不同默认操作。如WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN的评论中所示

        /** Adjustment option for {@link #softInputMode}: set to allow the
         * window to be resized when an input
         * method is shown, so that its contents are not covered by the input
         * method.  This can <em>not</em> be combined with
         * {@link #SOFT_INPUT_ADJUST_PAN}; if
         * neither of these are set, then the system will try to pick one or
         * the other depending on the contents of the window. If the window's
         * layout parameter flags include {@link #FLAG_FULLSCREEN}, this
         * value for {@link #softInputMode} will be ignored; the window will
         * not resize, but will stay fullscreen.
         */
        public static final int SOFT_INPUT_ADJUST_RESIZE = 0x10;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-02
      • 2017-01-09
      • 1970-01-01
      • 2015-04-06
      相关资源
      最近更新 更多