如何始终显示软键盘并且不让它关闭?

How to always show soft keyboard and do not let it be closed?

我想知道两件事

  1. 如何始终显示软键盘而不让它关闭(即使按下后退或确定按钮)?

  2. 我如何从中获取输入?

我已经尝试过此代码:

    EditText yourEditText= (EditText) findViewById(R.id.ed);
    InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);

具有这些变体:

  1. imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
  2. imm.toggleSoftInputFromWindow( yourEditText.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
  3. imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);

AndroidManifest.xml 文件中使用 android:windowSoftInputMode="stateAlwaysVisible"

像这样:

<activity android:name=".YourActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateAlwaysVisible" />  // OR stateVisible

If that activity having EditText so when ever Activity will start your Keyboard automatically open

如果你想在使用完成任何操作后仍然打开 Keyboad 然后通过 编程

InputMethodManager imm =
    (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInputFromWindow(
    linearLayout.getApplicationWindowToken(),
    InputMethodManager.SHOW_FORCED, 0);

显示软键盘

InputMethodManager imm = (InputMethodManager)
     getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(EDITABLE_VIEW,
     InputMethodManager.SHOW_IMPLICIT);

EDITABLE_VIEW 可以是任何聚焦在屏幕上的视图,如

mEditText = (EditText) findViewById(R.id.editText);
InputMethodManager imm = (InputMethodManager)
     getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mEditText ,
     InputMethodManager.SHOW_IMPLICIT);

((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInputFromInputMethod(editText.getWindowToken(), 0);

Documentation