点击别处隐藏输入法的方法
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (this.getCurrentFocus() != null) {
if (this.getCurrentFocus().getWindowToken() != null) {
InputMethodManager im =(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
im.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
}
}
return super.onTouchEvent(event);
}
参考文献:
1、http://www.cnblogs.com/changjl/p/4175539.html
2、http://8407832.blog.51cto.com/8397832/1403478
本文提供了一个在Android应用中点击空白区域隐藏软键盘输入法的示例代码。通过覆盖Activity的onTouchEvent方法并检查当前焦点视图,可以实现点击空白区域隐藏软键盘的功能。
514

被折叠的 条评论
为什么被折叠?



