代码之家  ›  专栏  ›  技术社区  ›  abrutsze

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

  •  -3
  • abrutsze  · 技术社区  · 7 年前

    我想知道两件事

    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\u IMPLICIT);
    1 回复  |  直到 7 年前
        1
  •  5
  •   ND1010_    7 年前

    使用 android:windowSoftInputMode="stateAlwaysVisible" 输入到 AndroidManifest.xml 文件

    这样地:

    <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