本文介绍了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
没有被触发 -
keydown
和keyup
始终包含keyCode=229
-
keypress
和input
被触发但不包含密钥 -
textInput
没有被触发 用户类型时, -
maxlength
属性(允许使用超过maxlength
个字符,并且仅在提交表单时才验证输入)
input[type=text]
上不使用keypress
isn't firedkeydown
andkeyup
always containkeyCode=229
keypress
andinput
are fired but don't contain the keytextInput
isn't firedmaxlength
attribute isn't honored oninput[type=text]
while the user types (more thanmaxlength
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输入按键不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!