Open softkeyboard when webview input text gets focus

586 Views Asked by At

I have a webview based app in which i want the appropriate keypad to open whenever i give focus to some input. With the code i have provided below it opens up but it always opens qwerty keypad even for numeric type inputs.

private void ShowKeyboard(final boolean show) {
    try {
        runOnUiThread(new Runnable() {
             @Override
             public void run() {
                 if (show) {
                      InputMethodManager mgr = (InputMethodManager) General.MainShellReference.getSystemService(Context.INPUT_METHOD_SERVICE);
                      mgr.showSoftInput(General.appView, InputMethodManager.SHOW_IMPLICIT);
                      ((InputMethodManager) General.MainShellReference.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(General.appView, 0);
                    } else {
                        getWindow().setSoftInputMode(
                                WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
                    }
            }
        });

    } catch (Exception ex) {
        ;
    }
}
1

There are 1 best solutions below

1
On

I think you have already tried to use <input type="number" /> and <input type="tel" />. Anyway try to do this.

Did you see this: Is there a way to have a masked numeric input field? http://blog.pamelafox.org/2012/05/triggering-numeric-keyboards-with-html5.html