从别人的项目中看到的,感觉挺有意思,先收藏着
/** * 隐藏软键盘 * hideSoftInputView * * @param * @return void * @throws * @Title: hideSoftInputView */ public void hideSoftInputView() { InputMethodManager manager = ((InputMethodManager) this.getSystemService(Activity.INPUT_METHOD_SERVICE)); if (getWindow().getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { if (getCurrentFocus() != null) manager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } } /** * 弹出输入法窗口 */ public void showSoftInputView(final EditText et) { new Handler().postDelayed(new Runnable() { @Override public void run() { ((InputMethodManager) et.getContext().getSystemService(Service.INPUT_METHOD_SERVICE)).toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); } }, 0); }