2014-03-05 145 views
2

我需要隐藏软键盘以响应点击按钮。 我看到了有关这一些帖子,我有尝试过:Android:隐藏软输入键盘

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); 

,但没有工作......

感谢您的帮助!

编辑: 找到解决办法。在下面发布。

回答

6

只要你不需要指向特定视图。我使用这个和工作:)

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

哦,很高兴知道,谢谢! – marius

0
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 

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

+0

不完全是我正在寻找,但谢谢你反正! :) – marius

2

一种解决方案是没有得到来自的EditText窗口的道理,但是从布敦至极隐藏键盘itselfs:

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