Custom bullet in editText inputType password

丶灬走出姿态 提交于 2019-12-11 16:52:40

问题


I need to create custom bullet for password for editText and put some padding between bullet symbols.

Is there some way to do this?


回答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:

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

and then set it like this:

textView.setTransformationMethod(new AsteriskPasswordTransformationMethod());

Source

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.



来源:https://stackoverflow.com/questions/32696868/custom-bullet-in-edittext-inputtype-password

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!