Android:隐藏软输入键盘
我需要隐藏软键盘以响应单击按钮。 我看到了一些关于这方面的帖子,我尝试了:Android:隐藏软输入键盘,android,android-softkeyboard,Android,Android Softkeyboard,我需要隐藏软键盘以响应单击按钮。 我看到了一些关于这方面的帖子,我尝试了: 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);
这很有效。但现在我有两个EditText视图。无论选择了哪个EditText,现在如何隐藏软键盘?我也试过了
InputMethodManager im = (InputMethodManager) getSystemService(
Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(myEditText1.getWindowToken(), 0);
im.hideSoftInputFromWindow(myEditText2.getWindowToken(), 0);
,但那没用
谢谢你的帮助
编辑:
找到了解决办法。贴在下面
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
您可以“玩”参数来实现任何您想要的。
希望这有帮助 解决方案是不从EditText获取窗口标记,而是从buton获取,buton隐藏键盘本身:
InputMethodManager im = (InputMethodManager) getSystemService(
Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(hideKeyboardButton.getWindowToken(), 0);
简单地说,你不需要提出具体的观点。我正在使用它,并且可以工作:)
不完全是我要找的,但无论如何谢谢你!:)
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);