[Android] Programmatically change input type of the EditText from PASSWORD to NORMAL

這還滿神奇的,有2個解法,一個是

Just for the people who are having same problem. Just add an extra attribute to that EditText programmatically and you are done.

password.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_VARIATION_PASSWORD);


另一個解法:

use this code to change password to text and vice versa

mCbShowPwd.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                // checkbox status is changed from uncheck to checked.
                if (!isChecked) {
                        // show password
                    mEtPwd.setTransformationMethod(PasswordTransformationMethod.getInstance());
                } else {
                        // hide password
                    mEtPwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
                }
            }
        });

for full sample code refer http://www.codeproject.com/Tips/518641/Show-hide-password-in-a-edit-text-view-password-ty

 

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *