我已经阅读安卓限制的EditText为数字和How做我展示在安卓一个EditText数字键盘。不幸的是,没有一个似乎符合我的需求。
I have read Android: Limiting EditText to numbers and How do I show the number keyboard on an EditText in android. Unfortunately, none of them seems to fit my needs.
我想限制我的EditText输入只有数字。不过,我也希望允许签名和/或十进制输入。
I want to restrict my EditText input to only numbers. However, I also want to allow signed and/or decimal input.
下面是我目前的code(我需要做编程):
Here is my current code (I need to do this programmatically):
EditText edit = new EditText(this);
edit.setHorizontallyScrolling(true);
edit.setInputType(InputType.TYPE_CLASS_NUMBER);
有了这个,我欢快的EditText限制所有输入阿拉伯数字。不幸的是,它不允许别的,像小数点。
With this, my EditText merrily restricts all input to numerical digits. Unfortunately, it doesn't allow anything else, like the decimal point.
如果我把上面一行 edit.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL)
的EditText上接受所有输入(这是不是我想要的...)。
If I change that line to edit.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL)
, the EditText accepts all input (which isn't what I want...).
我已经试过组合标志(在绝望中,看看它是否会工作):
I've tried combining flags (in desperation to see if it would work):
edit.setInputType(InputType.TYPE_CLASS_NUMBER);
edit.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL)
edit.setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED)
这也不能工作(的EditText上接受所有输入像往常一样)。
That didn't work either (the EditText accepted all input as usual).
那么,如何做到这一点?
So, how do I do this?
推荐答案
尝试使用TextView.setRawInputType()它对应的机器人:inputType
属性
相关推荐
最新文章