我正在显示一个文本输入对话框,如果没有打开硬键盘,我想自动显示软键盘。为了让它显示在我的三星 Galaxy Tab 上,我不得不使用 SHOW_FORCED 标志,但 SHOW_IMPLICIT 标志不起作用。此外,在对话框关闭时,如果我强制显示它,我想关闭键盘。但是,我在下面使用的代码不会关闭我的 Galaxy Tab 上的键盘;我认为这是因为我使用了 Explicit 标志来显示。
/* from the dialog constructor*/
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.restartInput(mEditText);
//only display if there is no hard keyboard out
Configuration config = getResources().getConfiguration();
if (config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES)
{
mForcedKeyboardDisplay = true;
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
/* from the onDismiss() method*/
//if we previously forced keyboard display, force it to close
if (mForcedKeyboardDisplay)
{
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.restartInput(mEditText);
imm.hideSoftInputFromWindow(mEditText.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
//this doesn't work either
//imm.hideSoftInputFromWindow(mEditText.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
//nor does this
//imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
}