配置android EditText以允许小数和负数

时间:2011-09-25 05:29:53

标签: android android-edittext decimal

我有一个Android EditText,我想让数字键盘出现。

如果我将android:inputType设置为numberSigned,我会得到数字键盘和键入负数的能力。但是这不会让我使用小数。如果我使用numberDecimal inputType,我可以使用小数而不是负数。

如何获得能够输入小数和负数的数字键盘?

6 个答案:

答案 0 :(得分:80)

你在EditText中错过了这个,

android:inputType="numberDecimal|numberSigned"

答案 1 :(得分:13)

我们可以使用,

edit_text.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);

如果我们需要以编程方式使用..

答案 2 :(得分:4)

查看此链接可能对您有所帮助 http://developer.android.com/resources/articles/creating-input-method.html

和android:inputtype的可能值是:

•none
•text
•textCapCharacters
•textCapWords
•textCapSentences
•textAutoCorrect
•textAutoComplete
•textMultiLine
•textImeMultiLine
•textNoSuggestions
•textUri
•textEmailAddress
•textEmailSubject
•textShortMessage
•textLongMessage
•textPersonName
•textPostalAddress
•textPassword
•textVisiblePassword
•textWebEditText
•textFilter
•textPhonetic
•textWebEmailAddress
•textWebPassword
•number
•numberSigned
•numberDecimal
•numberPassword
•phone
•datetime
•date
•time

答案 3 :(得分:1)

有些手机在同一个按钮中有小数和负数,因此无法进行否定。我想通过简单地添加 -

来分离按钮的方法
android:inputType="numberDecimal|numberSigned|textPersonName"

机器人:位数=" 0123456789 - "

这样你仍然有数字键盘布局,但负数和十进制按钮将是分开的,你不能使用任何其他数字混淆应用程序。

答案 4 :(得分:1)

经过测试,解决方案是

inputET.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);

答案 5 :(得分:0)

这通过编程为我工作了

editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);