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

Owe*_*ell 33 android decimal android-edittext

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

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

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

Lal*_*ani 84

你刚才在EditText中遗漏了这个,

android:inputType="numberDecimal|numberSigned"
Run Code Online (Sandbox Code Playgroud)


Ruk*_*ias 15

我们可以用,

edit_text.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
Run Code Online (Sandbox Code Playgroud)

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


kal*_*a c 5

看到此链接可能对您有帮助 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
Run Code Online (Sandbox Code Playgroud)