Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force keyboard with numbers in mobile website in Android

I have a mobile website and it has some HTML input elements in it, like this:

<input type="text" name="txtAccessoryCost" size="6" /> 

I have embedded the site into a WebView for possible Android 2.1 consumption, so that it will also be an Android application.

Is it possible to get the keyboard with numbers instead of the default one with letters when this HTML input element is focused?

Or, is it possible to set it for the whole application (maybe something in the Manifest file), if it is not feasible for an HTML element?

like image 295
ncakmak Avatar asked Jul 30 '10 14:07

ncakmak


People also ask

How do I get my Android keyboard to show numbers?

InputMethodManager imm = (InputMethodManager) getSystemService(Context. INPUT_METHOD_SERVICE); imm. toggleSoftInput(InputMethodManager. SHOW_FORCED,0);

How do you type numbers on Android?

To enable the number row, go to the keyboard Settings and tap on Typing. Under Typing, tap on Keys and enable Number row. Alternatively, enable the number row right from the shortcut settings available by tapping on Settings. The app also lets you customize the location of number pad in the symbols layout screen.

Which attribute is required to open only a numeric keyboard?

In testing on Android (both Chrome and the older Android Browser), Firefox for Android, and Windows Phone, the only way to trigger a big button keyboard is to ignore the W3C specification and use type="number" .


2 Answers

<input type="number" /> <input type="tel" /> 

Both of these present the numeric keypad when the input gains focus.

<input type="search" /> shows a normal keyboard with an extra search button

Everything else seems to bring up the standard keyboard.

like image 63
Richard Kernahan Avatar answered Oct 17 '22 19:10

Richard Kernahan


IMPORTANT NOTE

I am posting this as an answer, not a comment, as it is rather important info and it will attract more attention in this format.

As other fellows pointed, you can force a device to show you a numeric keyboard with type="number" / type="tel", but I must emphasize that you have to be extremely cautious with this.

If someone expects a number beginning with zeros, such as 000222, then she is likely to have trouble, as some browsers (desktop Chrome, for instance) will send to the server 222, which is not what she wants.

About type="tel" I can't say anything similar but personally I do not use it, as its behavior on different telephones can vary. I have confined myself to the simple pattern="[0-9]*" which do not work in Android

like image 29
Dmitry Koroliov Avatar answered Oct 17 '22 20:10

Dmitry Koroliov