Monday, 26 July 2021

Keyboard issues while using BaseInputConnection inside the Custom Webview Android

I have overridden the onCreateInputConnection inside the Custom WebView class like below

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);
    }
}

Some editable HTML content is loaded into the above Custom Webview, place the below sample editor.html in the asset folder

<html> 
<head></head>
<body contenteditable="true">

<h1> this is a sample text </h1></br>
<h2> h2 text</h1>

</body>
</html>

Main Issue when BaseInputConnection used in WebView: I am not able to perform glide typing or swipe letter typing using the keyboard. This behavior is observed only when BaseInputConnection is used whereas in default implementation glide typing is performed

Other issues when BaseInputConnection used in WebView In some devices like Redmi, the letters are not sent to the Webview while typing using soft keyboard.

I am overriding it to BaseInputConnection because it solves many of my problems in other use-cases. Any help on resolving the keyboard issue would be really appreciated



from Keyboard issues while using BaseInputConnection inside the Custom Webview Android

No comments:

Post a Comment