Android中的软键盘并不会随着输入的完成而关闭,因此我们需要一些手动的方法来进行操作。
一、隐藏软键盘
protected void hideInputMethod() {
View view = this.getCurrentFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
二、显示软键盘
protected void showInputMethod() {
View view = this.getCurrentFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
if (imm != null) {
imm.showSoftInput(view, 0);
}
}