【问题标题】:How to close momentarily the android keyboard whatever EditText currently active无论 EditText 当前处于活动状态,如何暂时关闭 android 键盘
【发布时间】:2014-10-07 14:29:34
【问题描述】:

我有一个带有各种EditText 和确认按钮的表单, 我需要当用户单击确认当前使用的EditText 时,键盘将暂时关闭,但如果用户尝试再次编辑其中一个 EditText,键盘会再次出现。

如果不添加大量代码行来分别控制每个EditText,我怎么能做到这一点?

【问题讨论】:

    标签: android android-softkeyboard android-keypad


    【解决方案1】:

    简单地使用 InputMethodManager

    这边

    InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
    

    【讨论】:

    • 完美!我会在 5 分钟倒计时后接受你的回答。谢谢。
    【解决方案2】:
     InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
                    //Find the currently focused view, so we can grab the correct window token from it.
     View view = getCurrentFocus();
    //If no view currently has focus, create a new one, just so we can grab a window token from it
     if(view == null) {
        view = new View(this);
     }
    inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
    

    这将关闭键盘,虽然我不确定键盘是否会为相同的编辑文本打开增益,但没有尝试过。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-04
      • 2014-12-30
      • 1970-01-01
      • 1970-01-01
      • 2022-12-19
      • 2011-09-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多