2011-09-25 61 views
26

我有一個Android EditText,我想讓數字鍵盤出現。配置android EditText以允許小數和負數

如果我將android:inputType設置爲numberSigned,我會得到數字鍵盤和輸入底片的能力。但是,這不會讓我使用小數。如果我使用numberDecimal inputType,我可以使用小數點但不是負數。

如何獲得數字鍵盤輸入小數和負數的能力?

回答

67

你只是在你的EditText缺少此,

android:inputType="numberDecimal|numberSigned" 
+1

哦哇這太簡單了。非常感謝! – Rabbit

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 
10

我們可以用,

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

如果我們需要以編程方式使用..