开发者

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 platfor开发者_Go百科ms 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.


I've also seen that adding ' pattern="[0-9]*" ' to your input tag. Try:

<input type="number" size="4" maxlength="4" pattern="[0-9]*" ></input>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜