【问题标题】:How to move the layoutFragment up when the soft keyboard is shown in android?android中显示软键盘时如何向上移动layoutFragment?
【发布时间】:2014-11-27 14:04:44
【问题描述】:

我有这个页面:

但是当打开softWareKeyBoard 时,我看不到其他EditText。我能做什么?

注意:我使用下面的代码但没有工作。我的classextends Fragment

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE|WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

【问题讨论】:

  • 查看问题的编辑答案

标签: android android-layout android-fragments fragment android-softkeyboard


【解决方案1】:

有两种方法可以做到这一点,您可以在清单活动中使用它

它会起作用的,调整盘会让你的表面向上流动并打开软键盘

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

<activity android:name="XXXActivity" android:windowSoftInputMode="adjustPan">
</activity>

【讨论】:

    【解决方案2】:

    只需在包含 Fragment 的 Activity 的 onCreate 方法中包含 window?.setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)(这将影响 Activity 中的所有 Fragment)

    例如:

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        window?.setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
        )
    }
    

    【讨论】:

      【解决方案3】:

      工作代码

      对于片段:

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

      对于活动:

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

      【讨论】:

        【解决方案4】:

        使用也可以使用NestedScrollView作为父视图。在清单文件中设置fitsSystemWindows = "false"android:windowSoftInputMode="adjustResize"

        【讨论】:

          【解决方案5】:

          我用这样的方式以编程方式显示软键盘,这对我来说可以防止在启动键盘时自动调整屏幕大小。

          EditText et =  (EditText))findViewById(R.id.edit_text);  
            Timer timer = new Timer();
                      TimerTask task = new TimerTask() {
          
                          @Override
                          public void run() {
                              InputMethodManager inputMethodManager=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                              inputMethodManager.toggleSoftInputFromWindow(et.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
          
                          }
                      };
                      timer.schedule(task, 200);
          

          在 Manifest 文件中使用:

          <activity android:name="XXXActivity" android:windowSoftInputMode="adjustPan">
          </activity>
          

          【讨论】:

            猜你喜欢
            • 2012-02-25
            • 2010-12-30
            • 1970-01-01
            • 2017-04-20
            • 2011-04-16
            • 2015-11-01
            • 1970-01-01
            • 2011-07-10
            相关资源
            最近更新 更多