有什么方法可以将密码文本从点(.)更改为星号(*).
Is there any way to change the password text from dot(.) to asterisk(*) .
密码正在编辑文本中输入.
Password is entering in edittext.
<EditText
android:id="@+id/passWord1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:inputType="number"
android:password="true"/>
在你的xml文件中插入edittext,
Insert edittext in your xml file,
<EditText
android:id="@+id/passWordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:inputType="textPassword"/>
你的类文件继续从edittext获取findViewById并为此实现,
and your class file go on and get findViewById from edittext and implement for this,
EditText edittext = (EditText)findViewById(R.id.passWordEditText);
edittext.setTransformationMethod(new AsteriskPasswordTransformationMethod());
这个类实现了,
public class AsteriskPasswordTransformationMethod extends PasswordTransformationMethod {
@Override
public CharSequence getTransformation(CharSequence source, View view) {
return new PasswordCharSequence(source);
}
private class PasswordCharSequence implements CharSequence {
private CharSequence mSource;
public PasswordCharSequence(CharSequence source) {
mSource = source; // Store char sequence
}
public char charAt(int index) {
return '*'; // This is the important part
}
public int length() {
return mSource.length(); // Return default
}
public CharSequence subSequence(int start, int end) {
return mSource.subSequence(start, end); // Return default
}
}
};
如果您的代码是 Kotlin,那么您必须制作单独的 java 文件,然后您必须将 java 与 kotlin 代码一起使用.
这篇关于将 EditText 密码掩码字符更改为星号 (*)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!