在自定义 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 (将#修改为@)