0
项目中遇到一些个问题,在这个页面点击一个EditText出现软键盘之后,点击按钮回到上一个页面,这时候软键盘没有关闭,这样就有点诡异了,今天就说说我的解决方案吧
1
网上也查到一些解决方案,比如在onResume中写以下代码
InputMethodManager imm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
if(imm.isActive()&&getCurrentFocus()!=null){
if (getCurrentFocus().getWindowToken()!=null) {
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
经实际检验没什么卵用,if里边根本就走不到,也可能是不符合我的这个场景吧
还有就是量实际高度的方法,那个没试验,比较复杂,这里分享一个经过我检测实际有用的方法
/**
* 关闭软键盘
*/
private void closeKeyboard() {
View view = getWindow().peekDecorView();
if (view != null) {
InputMethodManager inputMethodManager = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
这个方法,在你需要关闭的时候调一下就好了
发两个美女 哈哈哈