Android收起虚拟键盘

时间:2014-10-11 18:13:37   收藏:0   阅读:311

关于收起虚拟键盘,网上能找到的大多是这个:

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0) ;

不过这有个问题,比如我们在一个页面中有很多editText,到最后提交的时候我们并不知道实际光标停留在哪个editText。除非一个一个遍历判断。那么该怎么办呢?我后来找到这样的方法:

InputMethodManager imm =  (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE); 
if(imm != null) {
  imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
}

这个便不用提供绑定的editText。完美解决

原文:http://www.cnblogs.com/qq278360339/p/4019332.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!