2012-10-15 72 views
0

我有以下EditText,它是字符需要隱藏,因爲它是一個密碼。我可以用下面的方法做到這一點。如何將EditText設置爲密碼和數字鍵盤

<EditText 
     android:id="@+id/password" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:hint="Please Enter Password/Pin" 
     android:inputType="textPassword" 

     > 

我想鍵盤設置數值爲所有的密碼都是數字,但是當我這樣做是顯示的數字下面。我怎樣才能實現這兩個目標?

passwordPin = (EditText)findViewById(R.id.password); 
     passwordPin.setInputType(InputType.TYPE_CLASS_NUMBER); 

回答

2

已解決。

android:inputType="textPassword|number" 
android:password="true" 
+0

android:password is deprecated:Use inputType instead –

2

試試這個。

android:inputType="textPassword|number" 
+0

拉威爾謝謝,我無法找到它 – turtleboy

+0

@Ravel你好我剛剛測試過,我害怕,你可以看到的字符時輸入密碼字段。我怎樣才能讓他們隱藏。鍵盤部分很好。 – turtleboy

+0

@turtleboy它是仿真器或設備的一部分。我們無能爲力。 –

2

嘗試下面這行EditText

android:inputType="textPassword|number" 
+0

嗨,鍵盤是數字,但edittext不再是隱藏的字符。你可以看到字符 – turtleboy

2

通過Eclipse的展望,你也可以使用下面,不知道但它是如何向後兼容。

android:inputType="numberPassword" 
0

您可以通過編程,只要密碼現在已不這樣做。試試這個:

passwordPin = (EditText)findViewById(R.id.password); 
passwordPin.setInputType(InputType.TYPE_CLASS_NUMBER); 
editText.setTransformationMethod(PasswordTransformationMethod.getInstance()); 
相關問題