Skip to content Skip to sidebar Skip to footer

Custom Bullet In Edittext Inputtype Password

I need to create custom bullet for password for editText and put some padding between bullet symbols. Is there some way to do this?

Solution 1:

For changing the character that is displayed you can call the method setTransformationMethod (TransformationMethod method) and pass it a custom PasswordTransformationMethod.

This could look something like the following:

publicclassAsteriskPasswordTransformationMethodextendsPasswordTransformationMethod {
    @Overridepublic CharSequence getTransformation(CharSequence source, View view) {
        returnnewPasswordCharSequence(source);
    }
    privateclassPasswordCharSequenceimplementsCharSequence {
        private CharSequence mSource;
        publicPasswordCharSequence(CharSequence source) {
            mSource = source; // Store char sequence
        }
        publiccharcharAt(int index) {
            return'*'; // This is the important part
        }
        publicintlength() {
            return mSource.length(); // Return default
        }
        public CharSequence subSequence(int start, int end) {
            return mSource.subSequence(start, end); // Return default
        }
    }
};

and then set it like this:

textView.setTransformationMethod(newAsteriskPasswordTransformationMethod());

For changing the padding and such you should use either use textScaleX or if you are at API Level 21+ use letterSpacing in the XML.

Post a Comment for "Custom Bullet In Edittext Inputtype Password"