如何确保在编辑文本框中输入的文本不会向输入它的用户显示? IE。输入密码等时?
Activity 代码:
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" />
最佳答案
对于密码,您应该以编程方式使用
epass.setTransformationMethod(PasswordTransformationMethod.getInstance());
并在您的布局中使用
android:password="true"
请注意,根据TextView documents ,android:password
的编程版本是 setTransformationMethod()
,而不是 setInputType()
。
关于Android:如何隐藏在编辑文本框中输入的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25674711/