//如果软键盘打开
if(getWindow().getAttributes().softInputMode==WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED){
//隐藏
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
}
另外
public static void setHideInputMethod(Activity context) {
try {
InputMethodManager inputMethodManager = (InputMethodManager) context
.getApplicationContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(context
.getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
} catch (Exception e) {
}
}