Android : Typeface is changed when i apply password Type on EditText

前端 未结 6 1076
借酒劲吻你
借酒劲吻你 2021-02-01 12:53

I use FloatLabel library (https://github.com/weddingparty/AndroidFloatLabel) to add a little animation when user begin to write something in an EditText Android

6条回答
  •  不知归路
    2021-02-01 13:27

    It may be late to answer this question but i have came across this problem. So thought to answer this. I have solved it by Implementing a CustomTextWatcher.

    Here is the snippet

    private class CustomTextWatcher implements TextWatcher {
        private EditText mEditText;
    
        public CustomTextWatcher(EditText e) { 
            mEditText = e;
            mEditText.setTypeface(Typeface.DEFAULT);
        }
    
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            mEditText.setTypeface(Typeface.DEFAULT);
        }
    
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            mEditText.setTypeface(Typeface.MONOSPACE);
        }
    
        public void afterTextChanged(Editable s) { 
            if(s.length() <= 0){
                mEditText.setTypeface(Typeface.DEFAULT);
            } else {
                mEditText.setTypeface(Typeface.MONOSPACE);
            }
    
    
        }
    }
    

    Here is how you can use it in your application

    EditText pin = (EditText) findViewById(R.id.pin);
    pin.addTextChangedListener(new CustomTextWatcher(pin));
    

提交回复
热议问题