一直忘记怎么关闭如键盘,在这里做个笔记,以防再次忘记
一、
//得到InputMethodManager的实例
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm.isActive()) {
//如果开启
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS);
//关闭软键盘,开启方法相同,这个方法是切换开启与关闭状态的
}
if (imm.isActive()) {
//如果开启
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_NOT_ALWAYS);
//关闭软键盘,开启方法相同,这个方法是切换开启与关闭状态的
}
二、
InputMethodManager
im
=
(
InputMethodManager
)
getSystemService
(
Context
.
INPUT_METHOD_SERVICE
);
im . hideSoftInputFromWindow ( getCurrentFocus (). getApplicationWindowToken (), InputMethodManager . HIDE_NOT_ALWAYS );
im . hideSoftInputFromWindow ( getCurrentFocus (). getApplicationWindowToken (), InputMethodManager . HIDE_NOT_ALWAYS );