2014-09-04 102 views
1

如何確保輸入到編輯文本框中的文本不會顯示給輸入的用戶? 也就是說當輸入密碼等?Android:如何隱藏在編輯文本框中輸入的文本?

活動代碼:

  ePass = (EditText) findViewById(R.id.euPass); 


        String password = ePass.getText().toString(); 

XML:

<EditText 
      android:id="@+id/euPass" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="-2dp" 
      android:background="@drawable/edittext_bottom_bg" 
      android:drawableLeft="@drawable/password" 
      android:hint="Password" 
      android:padding="10dp" 
      android:password="true" 
      android:textColorHint="#bbbbbb" /> 

回答

0

口令使用:

android:inputType="textPassword" 

所以你的XML應該有:

<EditText 
      android:id="@+id/euPass" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="-2dp" 
      android:background="@drawable/edittext_bottom_bg" 
      android:drawableLeft="@drawable/password" 
      android:hint="Password" 
      android:padding="10dp" 
      android:password="true" 
      android:textColorHint="#bbbbbb" 
      android:inputType="textPassword"/> 
2

對於密碼,編程,你應該使用

epass.setTransformationMethod(PasswordTransformationMethod.getInstance()); 

而在你的佈局中使用

android:password="true" 

請注意,根據TextView documentsandroid:password的方案版本是setTransformationMethod(),不setInputType()

+1

看起來是一個完整和簡短的答案...額定 – MBH 2014-09-04 20:55:11

+0

謝謝,但是這仍然顯示在它填寫之前輸入的信件,我怎麼能得到它只是空白條目每次 – user3968848 2014-09-08 09:56:23

+0

我不認爲像這樣的東西是可能的。所以如果這個答案解決了你的問題,請接受它作爲一個正確的答案。如果它幫助你upvote它。 – 2014-09-08 20:09:35