The*_*ter 2 android onclick button android-softkeyboard
我有一个问题,如果用户输入并点击提交,键盘不会消失,所以我发现此代码来解决该问题(通过将其置于onClick方法):
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
Run Code Online (Sandbox Code Playgroud)
但是,如果用户手动关闭键盘,然后点击提交,我发现上面的代码会把键盘带回来 - 不好.
问题:
有更好的代码可供使用吗?或者,我可以说= =
if (keyboard = displayed) {
// do code above
} else {
// do nothing
}
Run Code Online (Sandbox Code Playgroud)
要隐藏键盘:
final InputMethodManager inputMethodManager =
(InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
Run Code Online (Sandbox Code Playgroud)
要表明:
final InputMethodManager inputMethodManager =
(InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(view, InputMethodManager.SHOW_FORCED);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2573 次 |
| 最近记录: |