Android WebView HTML输入按键不会触发 [英] Android WebView HTML input keypress doesn't fire

查看:185
本文介绍了Android WebView HTML输入按键不会触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些设备(主要是三星,但也有其他设备)以及以下各项的组合上:Android版本,WebView版本(即使使用Android 7中常绿的WebView)和键盘,也存在许多问题:

On some devices (mostly Samsung, but others too) and combinations of: Android version, WebView version (even with the evergreen WebView in Android 7) and keyboard, there are a number of issues:

  • keypress没有被触发
  • keydownkeyup始终包含keyCode=229
  • keypressinput被触发但不包含密钥
  • textInput没有被触发
  • 用户类型时,input[type=text]上不使用
  • maxlength属性(允许使用超过maxlength个字符,并且仅在提交表单时才验证输入)
  • keypress isn't fired
  • keydown and keyup always contain keyCode=229
  • keypress and input are fired but don't contain the key
  • textInput isn't fired
  • maxlength attribute isn't honored on input[type=text] while the user types (more than maxlength chars are allowed and the input is validated only when the form is submitted)

是否可以解决这些问题?

Is there a way to fix these issues?

推荐答案

我发现,如果扩展WebView并覆盖onCreateInputConnection,则所有这些问题均已解决:

I found that if you extend WebView and override onCreateInputConnection, all of those issues are fixed:

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之前:

覆盖onCreateInputConnection后(按g键):

这篇关于Android WebView HTML输入按键不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆