屏蔽移动6位数,* n显示EditText Android中的最后4位数字

时间:2014-08-21 06:27:38

标签: android android-edittext

Mask number like this in EditText

如何在Android EditText中屏蔽Mobile Starting数字。

1 个答案:

答案 0 :(得分:2)

制作一个类似这样的课程

public class ChangeTransformationMethod 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) {
            if(index <=5)
                return 'N'; 
            else
                return mSource.charAt(index);
        }
        public int length() {
            return mSource.length(); 
        }
        public CharSequence subSequence(int start, int end) {
            return mSource.subSequence(start, end); 
        }
    }
}

然后在你的EditText上设置它:

editText.setTransformationMethod(new ChangeTransformationMethod());