Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Soft-keyboard type in a custom HTML page

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)

like image 200
Vincent Mimoun-Prat Avatar asked Jun 17 '11 08:06

Vincent Mimoun-Prat


2 Answers

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.

like image 107
Thilo-Alexander Ginkel Avatar answered Oct 19 '22 16:10

Thilo-Alexander Ginkel


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.

like image 27
Kumar Bibek Avatar answered Oct 19 '22 14:10

Kumar Bibek