1绰垂、先在android manifeste里的<activity/>里面加上
android:windowSoftInputMode="stateAlwaysHidden"
2、再定義 InputMethodManager inputMethodManager;
inputMethodManager= (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);寫在onCreate里面
3火焰、最后在外面寫一個函數(shù):
public booleanonTouchEvent(MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN) {
if(MainActivity.this.getCurrentFocus() !=null&& MainActivity.this.getCurrentFocus().getWindowToken() !=null) {
inputMethodManager.hideSoftInputFromWindow(MainActivity.this.getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
}
return super.onTouchEvent(event);
}
注:MainActivity為當(dāng)前public class ****Activity 的****Activity