如何解决在自定义 Webview Android
我已经覆盖了自定义 WebView 类中的 onCreateInputConnection,如下所示
class CustomWebView extends WebView {
public CustomWebView(@Nullable Context context) {
super(context);
loadUrl("file:///android_asset/editor.html")
}
public CustomWebView(@Nullable Context context,@Nullable AttributeSet attrs) {
super(context,attrs);
loadUrl("file:///android_asset/editor.html")
}
public CustomWebView(@Nullable Context context,@Nullable AttributeSet attrs,int defStyleAttr) {
super(context,attrs,defStyleAttr);
loadUrl("file:///android_asset/editor.html")
}
@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
// below return statement would be the default implementation
// return super.onCreateInputConnection(outAttrs)
return new BaseInputConnection(this,false);
}
}
一些可编辑的 HTML 内容被加载到上面的自定义 Webview 中,将下面的示例 editor.html 放在资产文件夹中
<html>
<head></head>
<body contenteditable="true">
<h1> this is a sample text </h1></br>
<h2> h2 text</h1>
</body>
</html>
在 WebView 中使用 BaseInputConnection 时的主要问题: 我无法使用键盘执行滑行打字或滑动字母打字。仅当使用 BaseInputConnection 而在默认实现中执行滑动键入时才会观察到此行为
在 WebView 中使用 BaseInputConnection 时的其他问题 在某些设备(如 Redmi)中,使用软键盘打字时,字母不会发送到 Webview。
我将它覆盖到 BaseInputConnection 因为它解决了我在其他用例中的许多问题。对解决键盘问题的任何帮助将不胜感激
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。