【发布时间】:2014-04-24 11:01:21
【问题描述】:
我想知道在用户按下按钮后如何最好地隐藏屏幕(软?)键盘。当用户在提交之前输入文本时,他们的键盘可能仍然可见,我想缩小他们提交时的窗口。
我已找到问题here 和here 的答案,但似乎都无法正常工作。尽管 Toast 通知显示在顶部,但它们的键盘仍然可见。
为了清楚起见,我的代码:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromInputMethod(getCurrentFocus().getWindowToken(), 0);
我也试过了:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromInputMethod(((EditText)findViewById(R.id.txtToWrite)).getWindowToken(), InputMethodManager.0);
【问题讨论】:
标签: android keyboard android-softkeyboard android-input-method