A COMPREHENSIVE GUIDE FOR DESIGNING, DEVELOPING, DEBUGGING, AND DISTRIBUTING ANDROID APPLICATIONS.
Change dot to Asterisk in Password
In this tutorial, I will show you how to change the default value for password which is dot(.) to asterisk(*). See the code below.
//create a child class of your main class
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
}
}
};
//then call this class wherever you need to change the dot to asterisk.
final EditText et_pin1 = (EditText)dl.findViewById(R.id.et_verify1);et_pin1.setTransformationMethod(new AsteriskPasswordTransformationMethod());
That's it, hope this simple tutorial will help you something. Happy Coding
No comments:
Post a Comment