Android WebView HTML input keypress doesn't fire


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 isn’t fired
  • keydown and keyup always contain keyCode=229
  • keypress and input are fired but don’t contain the key
  • textInput isn’t fired
  • maxlength attribute isn’t honored on input[type=text] while the user types (more than maxlength chars are allowed and the input is validated only when the form is submitted)

Is there a way to fix these issues?


I found that if you extend WebView and override onCreateInputConnection, all of those issues are fixed:

public class WebViewExtended extends WebView {
    public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
        // This line fixes some issues but introduces others, YMMV.
        // super.onCreateInputConnection(outAttrs);

        return new BaseInputConnection(this, false);

Before overriding onCreateInputConnection:


After overriding onCreateInputConnection (g was pressed):


Answered By – gabrielmaldi

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published