直接加上下面這個方法,搞定了
//觸摸屏幕就關閉輸入法
@Override
public boolean onTouchEvent(MotionEvent event) {
InputMethodManager imm = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
// 顯示或者隱藏輸入法
imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
return true;
}