Android keyboard not showing when clicking on input in webview

Please try to add these lines to your webview in the XML file.

android:focusable="true"
android:focusableInTouchMode="true"

Hope it helps.


In my case, apart from adding

android:focusable="true"
android:focusableInTouchMode="true"

I also needed to subclass WebView and add this method

@Override
public boolean onCheckIsTextEditor() {
    return true;
}

I got the solution from this thread where many other solutions are proposed.

This is the entire WebView subclass, if someone wants to use it

public class CustomWebView extends WebView {
    public CustomWebView(Context context) {
        super(context);

        init();
    }

    public CustomWebView(Context context, AttributeSet attrs) {
        super(context, attrs);

        init();
    }

    public CustomWebView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        init();
    }

    protected void init() {
        setFocusable(true);
        setFocusableInTouchMode(true);
    }

    @Override
    public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
        BaseInputConnection baseInputConnection = new BaseInputConnection(this, false);
        outAttrs.imeOptions = IME_ACTION_DONE;
        outAttrs.inputType = TYPE_CLASS_TEXT;
        return baseInputConnection;
    }

    @Override
    public boolean onCheckIsTextEditor() {
        return true;
    }
}