Convert Password Characters into a placeholder character.
Overview
This code is used to covert password characters into an Asterisk. To do that you have to create a class and extend the class with PasswordTransformationMethod
public class AsteriskMethod extends PasswordTransformationMethod {
public CharSequence mPassword;
@Override
public CharSequence getTransformation(CharSequence source, View view) {
return new AsteriskMethod.PasswordCharSequence(source);
}
private class PasswordCharSequence implements CharSequence {
public PasswordCharSequence(CharSequence source) {
mPassword = source;
// Store char sequence
}
public char charAt(int index) {
return '*'; // This is the important part
}
public int length() {
return mPassword.length(); // Return default
}
public CharSequence subSequence(int start, int end) {
return mPassword.subSequence(start, end); // Return default
}
}
}
To use this class, you can use the following code
inputUserPassword.setTransformationMethod(new AsteriskMethod()); // inputUserPassword is an EditText
Comments
Post a Comment