Activity中点击空白处隐藏键盘

在activity页面设置点击空白 收起键盘(直接替换类名就好)

@Override
public boolean onTouchEvent(MotionEvent event) {    
    InputMethodManager imm = (InputMethodManager)           getSystemService(Context.INPUT_METHOD_SERVICE);
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        if (MainActivity.this.getCurrentFocus().getWindowToken() != null) {
                   imm.hideSoftInputFromWindow(MainActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }
        return super.onTouchEvent(event);
}

 

你可能感兴趣的:(android)