在某些设备(主要是三星,但也有其他设备)上以及以下组合:Android 版本、WebView 版本(即使使用 Android 7 中的常青 WebView)和键盘,存在许多问题:
keypress
没有触发keydown
和keyup
始终包含keyCode=229
keypress
和input
被触发但不包含键textInput
未触发maxlength
属性在input[type=text]
上不被接受,而用户类型(允许超过maxlength
个字符并且只有在提交表单时才会验证输入)
有没有办法解决这些问题?
最佳答案
我发现如果您扩展 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
之前:
覆盖 onCreateInputConnection
后(g
被按下):
关于javascript - Android WebView HTML 输入按键不会触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45312553/