问题
In my application, I am using the below passwordTransformationClass
for showing the password in asterisk format. The problem is, I want a space after each text in the edit text, i.e. a space after every asterisk. But the overridden methods don’t take space except a single asterisk character.
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
}
}
}
回答1:
Input : <*****>
I hope this is your input in EditTextView and you want to transform the EditTextView text to something like
Output: <* * * * *>
then set some custom EditTextView fonts which have much spacing between characters...
Change font for EditText in Android?
and if you are going through Editext.addTextChangedListener, we can do it but we have to write down some expensive Logics into it to handle copy, paste, backspace and so many other occurrences .. :)
回答2:
Try to change the code from
public char charAt(int index)
{
return '*'; // This is the important part
}
to
public string charAt(int index)
{
return "* "; // This is the important part
}
来源:https://stackoverflow.com/questions/38197773/put-a-space-after-transforming-the-password-text-into-asterisks