Android WebView HTML输入按键不会触发

时间:2017-07-25 20:06:07

标签: javascript java android input webview

在某些设备上(主要是三星,但也包括其他设备)和以下组合:Android版,WebView版(即使是Android 7中常绿的WebView)和键盘,还有很多问题:

  • keypress未被解雇
  • keydownkeyup始终包含keyCode=229
  • keypressinput被解雇,但不包含密钥
  • textInput未被解雇
  • 当用户输入{允许超过maxlength个字符并且仅在提交表单时验证输入时,{li> input[type=text]属性未在maxlength上兑现。

有没有办法解决这些问题?

1 个答案:

答案 0 :(得分:2)

我发现,如果您延长WebView并覆盖onCreateInputConnection,则所有这些问题都会得到解决:

public class WebViewExtended extends WebView {
    @Override
    public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
        // This line fixes some issues but introduces others, YMMV.
        // super.onCreateInputConnection(outAttrs);

        return new BaseInputConnection(this, false);
    }
}

在覆盖onCreateInputConnection

之前

before

覆盖onCreateInputConnection后(g被按下):

after

相关问题