Is there any way to specify which soft keyboard layout (I need only numbers) is shown when the user taps on a text input field in an HTML page?
I can change the HTML page and the Javacode (I have an activity embedding a WebView). However, it must not affect other platforms if I change the HTML code (another browser/device should still interpret the input field properly and show a soft keyboard, not necessarly a numbers only keyboard)
I did not try this, but in theory it should work:
Use the HTML5 type
attribute for the <input>
tag to declare the field as accepting only numbers. This will give the browser the hint to display a numeric keyboard. To have this only take effect on Android devices, consider emitting some Android-specific Javascript (which could either do the platform detection on the client through the user agent or which could alternatively only be sent by the server if that detects and Android device - again using the user agent header), which traverses through all input elements (maybe marked with a special class) and sets the type
to number
.
They seem to work differently in different devices and OS versions. It basically depends on the WebKit version that runs on a device. If it supports those tags, it will work, else, it ignores that tag.
On 2.3.4, on My Nexus S, type = number, gives a numeric keypad.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With