简体   繁体   中英

Numeric Soft Keyboard on Android

I am developing an android application where we are using WebView to display Web page being served from Web Server. Everything is working fine except with the problem that when i am using the soft keyboard and switched to numeric key entry and move from first field to next field, the keyboard layout automatically changed to alphanumeric.

Is there any way using which i can pull up virtual keyboard in numeric mode only when i need to enter numbers only?

Thanks and Regards.

editTextField.setRawInputType(Configuration.KEYBOARD_QWERTY);

This shows the normal key pad with the numeric version first, yet allows you to switch between them.

getInput.setRawInputType(Configuration.KEYBOARD_12KEY);

This shows numeric only, with no option to enter text values.

I ran into a similar situation. I wanted numeric values only, but I have a "hint" that was text. Setting the inputType to number would not allow the hint to be displayed. This works around it fine.

Configuration.KEYBOARD_12KEY or Configuration.KEYBOARD_QWERTY is wrong way.

You have to use InputType (show doc here) on the EditText setRawInputType() .

If you are talking about HTML, you could use HTML5 features, for example:

Number: <input type="number" name="points" min="1" max="10" />

Have tested this in HTC Desire browser, and it brings up different (numeric) keyboard when you enter data into such field.

Is there any way using which i can pull up virtual keyboard in numeric mode only when i need to enter numbers only?

Yes, you can specify android:inputType XML attribute with the number or numberDecimal value:

<EditText 
android:text="" 
android:id="@+id/editTextNumber" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:inputType="numberDecimal">
</EditText>

Enjoy!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM