【问题标题】:Android : softkeyboard does not consume input event / touchAndroid:软键盘不消耗输入事件/触摸
【发布时间】:2016-04-15 18:49:34
【问题描述】:

我正在开发一个处于横向模式的应用程序。

当我以编程方式打开默认键盘时,它不会在横向模式下消耗任何输入事件(打开键盘但不显示任何键盘点击预览)。但是,如果我以纵向打开默认键盘,它会打开键盘并显示我单击的键的预览,即它在纵向模式下按预期工作。

我不知道为什么它在横向模式下不接受输入。

这是我打开键盘的方式。

final InputMethodManager inputMethodManager = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

另外,如果我指定名为 InputMethodManager.SHOW_IMPLICIT 的标志,它甚至不会显示键盘。

【问题讨论】:

    标签: android keyboard landscape android-input-method


    【解决方案1】:

    阅读:

    How to show soft-keyboard when edittext is focused

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

    记得放

    <activity
    [...]
    android:windowSoftInputMode="adjustPan"
    [...]
    >
    

    在您的清单中

    【讨论】:

      【解决方案2】:

      结合自定义视图,我遇到了完全相同的问题。

      为了解决这个问题,我需要在自定义视图中实现 onCreateInputConnection 以将 InputType 设置为 TYPE_CLASS_TEXT。

      如果您需要为退格键捕获 onKeyDown 和 onKeyUp 事件,您可以使用 TYPE_TEXT_VARIATION_NORMAL。

      这里是一个例子:

      /**
       * needed make softkeyboard work in landscape mode and to capture backspace.
       */
      @Override
      public InputConnection onCreateInputConnection(EditorInfo outAttrs){
          outAttrs.inputType = InputType.TYPE_TEXT_VARIATION_NORMAL;
          outAttrs.imeOptions = EditorInfo.IME_ACTION_NONE | EditorInfo.IME_FLAG_NO_FULLSCREEN;
          return null;
      }
      

      【讨论】:

        猜你喜欢
        • 2018-01-19
        • 2020-09-18
        • 1970-01-01
        • 2018-07-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多