Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase inputType password dot size in android

I have an EditText whose inputType is numberPassword. I want to change the dot size which replaces the text. It is quite small(android default) for my purpose. I want to increase the dot size. How can I achieve that ?

like image 335
sagar suri Avatar asked Jan 09 '18 06:01

sagar suri


2 Answers

The solution provided half works, the problem is that that transformation will transform the text directly to the '*' while the expected behavior is to hide the char once a new char has been input or after a few seconds so the user gets the chance to see the real char before hiding it. If you want to keep the default behavior you should do something like this:

/**
 * A transformation to increase the size of the dots displayed in the text.
 */
private object BiggerDotPasswordTransformationMethod : PasswordTransformationMethod() {

    override fun getTransformation(source: CharSequence, view: View): CharSequence {
        return PasswordCharSequence(super.getTransformation(source, view))
    }

    private class PasswordCharSequence(
        val transformation: CharSequence
    ) : CharSequence by transformation {
        override fun get(index: Int): Char = if (transformation[index] == DOT) {
            BIGGER_DOT
        } else {
            transformation[index]
        }
    }

    private const val DOT = '\u2022'
    private const val BIGGER_DOT = '●'
}

This will replace the original dot with whatever char you want.

like image 189
dan87 Avatar answered Oct 11 '22 02:10

dan87


Try to replace asterisk with this ascii codes.
⚫ - ⚫ - Medium Black Circle ⬤ - &#11044 - Black Large Circle

What would be the Unicode character for big bullet in the middle of the character?

 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
        }
    }
}; 

text.setTransformationMethod(new MyPasswordTransformationMethod());
like image 35
anddevmanu Avatar answered Oct 11 '22 02:10

anddevmanu