软输入模式不能设置为隐藏



我创建了一个带有对话框主题的活动,它有一个编辑文本。我不想在每个活动上显示软输入,所以我在该活动上使用以下代码:

 EditText editTextData=GetView(R.id.txtData);
    editTextPin.requestFocus();
    InputMethodManager mgr = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    mgr.showSoftInput(editTextData, InputMethodManager.SHOW_IMPLICIT);

这使输入键盘可见。输入后,我尝试使用以下代码将其隐藏:

 InputMethodManager mgr = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
        mgr.hideSoftInputFromInputMethod(editTextData.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);

它仍然可见。我还应该打电话给什么?

试试..

mgr.hideSoftInputFromInputMethod(editTextData.getWindowToken(), 1);

尝试

InputMethodManager

mgr = (InputMethodManager)getSystemService( Context.INPUT_METHOD_SERVICE);mgr.hideSoftInputFromWindow(editTextData.getWindowToken(), 0);

您可以使用

以下函数来隐藏键盘。

private void hideSoftKeyboard(Activity act) {
    InputMethodManager inputMethodManager = (InputMethodManager) act.getSystemService(Context.INPUT_METHOD_SERVICE);
    inputMethodManager.hideSoftInputFromWindow(act.getCurrentFocus().getWindowToken(), 0);
}

希望对您有所帮助。

最新更新