【问题标题】:softkeyboard pop up while there are no editable widgets?没有可编辑的小部件时弹出软键盘?
【发布时间】:2012-01-09 09:17:55
【问题描述】:

我遇到了一个问题。当我登录我的应用程序(从登录页面到主页)时,主页中没有任何可编辑的小部件,但键盘会自动弹出,我不想这样做, 如何解决?谢谢

【问题讨论】:

    标签: android android-widget android-manifest


    【解决方案1】:

    来自Close/hide the Android Soft Keyboard

    您可以强制 Android 使用 InputMethodManager,调用 hideSoftInputFromWindow,传入 包含您的编辑字段的窗口的标记。

    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
    

    这将强制键盘在所有情况下都隐藏。在一些 您想要传递的案例InputMethodManager.HIDE_IMPLICIT_ONLY 作为第二个参数,以确保您仅在 用户没有明确地强制它出现(通过按住菜单)。

    【讨论】:

      【解决方案2】:

      试试这个。

      InputMethodManager inputManager = (InputMethodManager) (YourActivity)
                                  .getSystemService(Context.INPUT_METHOD_SERVICE);
                          inputManager.hideSoftInputFromWindow(home.getCurrentFocus()
                                  .getWindowToken(),
                                  InputMethodManager.HIDE_NOT_ALWAYS);
      

      【讨论】:

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