2014-09-04 75 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

相关问题