Edittext Fonts Are Not Displaying

元气小坏坏 提交于 2019-12-01 18:56:02
Andrew Schuster

It seems that the font that you have included does not contain a character for the symbol used by default for password transformation. You have two options:

  1. Use a different font

  2. Change the mask character to something that the font does contain.

Because I speculate you're not a quitter, here's some code that will change the mask character from a dot ( ) to an asterisk ( * ).

First you must make your own PasswordTransformationMethod to override the default:

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) {
            // This is where we make it an asterisk.  If you wish to use 
            // something else then change what this returns
            return '*'; 
        }
        public int length() {
            return mSource.length(); // Return default
        }
        public CharSequence subSequence(int start, int end) {
            return mSource.subSequence(start, end); // Return default
        }
    }
};

Finally you set your new transformation method to the EditText you wish to mask.

edt_password = (EditText)findViewById(R.id.edt_password);
edt_password.setTransformationMethod(new AsteriskPasswordTransformationMethod());

I used information from this question.

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