安卓Edittext 密码样式

2024-02-28  本文已影响0人  不会弹钢琴de大叔

将edittext中密码输入框的原点变为*

public void setEditTextPassWordShowStyle(EditText et) {
    et.setTransformationMethod(new PasswordCharSequenceStyle());
}

public class PasswordCharSequenceStyle 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;
        }

        public char charAt(int index) {
            return '*';
        }

        public int length() {
            return mSource.length();
        }

        public CharSequence subSequence(int start, int end) {
            return mSource.subSequence(start, end);
        }
    }
}
上一篇下一篇

猜你喜欢

热点阅读