解决方案结果如下.要在DialogFragment中显示键盘:
@Override public void onResume() { super.onResume(); editText.post(new Runnable() { @Override public void run() { editText.requestFocus(); InputMethodManager imm = (InputMethodManager)editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); if (imm != null) imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); } }); }
要隐藏它,请使用@Shekhar上面的解决方案
@Override public void onDismiss(DialogInterface dialog) { InputMethodManager imm = (InputMethodManager)editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); if (imm.isActive()) imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS); super.onDismiss(dialog); }