点击EditText以外的地方软键盘隐藏

来源:互联网 发布:mysql中外键约束 编辑:程序博客网 时间:2024/05/16 13:35

实现代码如下:

//点击任意位置,取消键盘显示

public void CloseKeyBoard() {
if (getCurrentFocus() != null
&& getCurrentFocus().getWindowToken() != null) {
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
View v = getCurrentFocus();
if (v != null) {
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}

}


此外:一个应用中可能多个页面都会有涉及到此功能:点击EditText以外的地方软键盘隐藏;那么专门写一个类,比如叫BWActivity,这个类的功能是:将Activity的共性表现出来,这样所有涉及到“点击EditText以外的地方软键盘隐藏”的Activity都继承BWActivity就可以了。




涉及到:点击EditText以外的地方软键盘隐藏”的页面都继承BWActivity就可以了








0 0
原创粉丝点击