Android 上的数字软键盘

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3216169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:10:53  来源:igfitidea点击:

Numeric Soft Keyboard on Android

androidkeyboard

提问by Shivaansh Gupta

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.

我正在开发一个 android 应用程序,我们使用 WebView 来显示从 Web 服务器提供的网页。一切正常,除了当我使用软键盘并切换到数字键输入并从第一个字段移动到下一个字段时,键盘布局自动更改为字母数字的问题。

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.

感谢致敬。

回答by user455451

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.

我遇到了类似的情况。我只想要数值,但我有一个“提示”是文本。将 inputType 设置为 number 将不允许显示提示。这很好地解决了它。

回答by fazermokeur

Configuration.KEYBOARD_12KEYor Configuration.KEYBOARD_QWERTYis wrong way.

Configuration.KEYBOARD_12KEY或者Configuration.KEYBOARD_QWERTY是错误的方式。

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

你必须使用的inputType(这里显示DOC)EditText setRawInputType()

回答by altumano

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

如果您在谈论 HTML,您可以使用 HTML5 功能,例如:

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.

在 HTC Desire 浏览器中对此进行了测试,当您在该字段中输入数据时,它会显示不同的(数字)键盘。

回答by Paresh Mayani

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:inputTypeXML attribute with the numberor numberDecimalvalue:

是的,您可以使用或值指定android:inputTypeXML 属性:numbernumberDecimal

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

Enjoy!!

享受!!