美文网首页
安卓Edittext 密码样式

安卓Edittext 密码样式

作者: 不会弹钢琴de大叔 | 来源:发表于2024-02-28 09:46 被阅读0次

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

    相关文章

      网友评论

          本文标题:安卓Edittext 密码样式

          本文链接:https://www.haomeiwen.com/subject/xcnxzdtx.html