I am trying to show in asterisk (*)
symbol in place of dots in EditText
having inputType
as textPassword
. I came across post that ask to use setTransformationMethod()
and implement PasswordTransformationMethod
. But which method I of that class need I implement and how show asterisk? Is there other way to do that?
Thanks
The android:inputType attribute allows you to specify various behaviors for the input method. Most importantly, if your text field is intended for basic text input (such as for a text message), you should enable auto spelling correction with the "textAutoCorrect" value.
change the edittext input type property to text password in xml. Show activity on this post. As the original poster mentioned in a comment, calling setSingleLine (boolean singleLine) resets the EditText settings, so you'll have to call that first and after that set custom settings like the password InputType .
Use android:inputType="number" in XML can also input float.
I think you should go through the documentation. Create your PasswordTransformationMethod
class, and in the getTransformation()
method, just return a string of *
characters that is the same length as the contents of your password field.
I did some fiddling and came up with an anonymous class that worked for me to make a field full of *
s. I converted it into a usable class here:
public class MyPasswordTransformationMethod 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
}
}
};
// Call the above class using this:
text.setTransformationMethod(new MyPasswordTransformationMethod());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With