Change dot to Asterisk in Password

Web Hosting
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 {
    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(;et_pin1.setTransformationMethod(new AsteriskPasswordTransformationMethod());

That's it, hope this simple tutorial will help you something. Happy Coding

No comments:

Post a Comment