android 关闭软键盘有两种方案
方案1:
建议在 onPause 里调用,或页面有多个 edittext 时按需调用
public static void hideKeyboard(Activity activity){
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
View v = activity.getWindow().peekDecorView();
if (null != v) {
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}
方案2:
建议只有一个edittext时调用
public static void hideKeyboard(Activity activity, View view){
if(activity==null||view==null){
return;
}
InputMethodManager imm=(InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(),0);
}