问题描述
我正在开发一个科学应用程序,并且我有一个EditText,因此我必须输入一个输入数值,所以inputType是"number | numberSigned | numberDecimal",但是问题是当我想输入科学计数法数字时像"45.6E05"一样,由于EditText的InputType,我无法输入"E"字符.
I'm developing an science app, and I have an EditText in wich I must enter an input numeric value, so the inputType is "number|numberSigned|numberDecimal", but the problem is when I want input a scientific notation number like "45.6E05", I can't input "E" character because of EditText's InputType.
当EditText聚焦时,如何允许"E"字符并仅显示数字键盘?
How can to allow "E" character and only to show a numerical keyboard when the EditText is focused?
推荐答案
无法显示带有额外字母E
的数字键盘,解决该问题的两种方法是使按钮输入E
到您的edittext或使用android:digits
属性,例如:
There is no way to show the numerical keyboard with an extra letter E
on it, two ways around this are either make a button that inputs E
to your edittext or to use the android:digits
attribute like such:
android:digits="1234567890E."
括号中的所有字符都是您希望用户能够输入的字符
Where all the characters in the brackets are the ones that you want the user to be able to input
要使用按钮进行操作,只需在其onClickListener
中放入以下代码
To make do it using a button, in its onClickListener
you just need to put the following code
edittext.setText(edittext.getText().toString() + "E"
另一方面,如果要在光标位置插入字符,则应尝试使用此字符(取自)
In the other hand if you want to insert the character in the position of the cursor then you should try this (taken from here)
int start =edittext.getSelectionStart();
String s = "E";
edittext.getText().insert(start, s);
这篇关于如何在Android数字键盘中允许特定字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!