Edittext Fonts Are Not Displaying

前端 未结 1 1138
时光取名叫无心
时光取名叫无心 2021-01-19 10:13

I\'m going through a weird problem.

I have created CustomEdittext class for setting Typeface for whole application and it works success

1条回答
  •  醉话见心
    2021-01-19 10:46

    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.

    0 讨论(0)
提交回复
热议问题