【问题标题】:How to always show soft keyboard and do not let it be closed?如何始终显示软键盘而不让它被关闭?
【发布时间】:2018-05-29 07:42:52
【问题描述】:

我想知道两件事

  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);

【问题讨论】:

  • 你可以检查一下。 link。谢谢:)

标签: android android-edittext keyboard android-keypad window-soft-input-mode


【解决方案1】:

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

像这样:

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

如果该活动具有EditText,那么活动何时开始 你的键盘会自动打开

如果您想在使用完成任何操作后仍打开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

【讨论】:

  • 是的,按下后退或确定按钮后它们都会关闭。
  • 你也试试把&lt;activity android:name=".YourActivity" android:label="@string/app_name" android:windowSoftInputMode="stateAlwaysVisible" /&gt;这个并应用所有三种方式,如果有任何变化,请告诉我
  • 是的,当然,但没有结果
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-27
  • 1970-01-01
  • 2012-05-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-07
相关资源
最近更新 更多