【问题标题】:Android: Hide soft input keyboardAndroid:隐藏软输入键盘
【发布时间】:2014-04-07 15:04:52
【问题描述】:

我需要隐藏软键盘以响应单击按钮。 我看到了一些关于这个的帖子,我尝试了一下:

InputMethodManager im = (InputMethodManager) getSystemService(
    Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(myEditText1.getWindowToken(), 0);

效果很好。但现在我有两个 EditText 视图。无论选择了哪个 EditText,我现在如何隐藏软键盘?我也试过了

InputMethodManager im = (InputMethodManager) getSystemService(
    Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(myEditText1.getWindowToken(), 0);
im.hideSoftInputFromWindow(myEditText2.getWindowToken(), 0);

,但是没有用...

感谢您的帮助!

编辑: 找到解决方案。发布在下面。

【问题讨论】:

    标签: android android-softkeyboard


    【解决方案1】:

    只是你不需要指出具体的观点。我正在使用它并且可以工作:)

    InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
    

    【讨论】:

      【解决方案2】:

      一种解决方案是不从 EditText 中获取窗口令牌,而是从隐藏键盘本身的按钮中获取:

      InputMethodManager im = (InputMethodManager) getSystemService(
          Context.INPUT_METHOD_SERVICE);
      im.hideSoftInputFromWindow(hideKeyboardButton.getWindowToken(), 0);
      

      【讨论】:

        【解决方案3】:
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        

        你可以“玩”这个参数来实现你想要的任何东西。 希望这有帮助!

        【讨论】:

        • 不完全是我正在寻找的东西,但还是谢谢你! :)
        猜你喜欢
        • 2012-10-30
        • 1970-01-01
        • 2022-12-14
        • 2019-06-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-06
        • 1970-01-01
        相关资源
        最近更新 更多