Android文本输入框(EditText)切换密码的显示与隐藏


private voidchangPwdEditTextStatus() {

//TODO 判断标记是否存在

booleanflag = (mEtPassword.getTag() ==null);

//TODO 设置EditText文本为可见的  或 不可见

mEtPassword.setTransformationMethod(flag ? HideReturnsTransformationMethod.getInstance() : PasswordTransformationMethod.getInstance());

//TODO 设置标记

mEtPassword.setTag(flag ?"":null);

//TODO 切换后将EditText光标置于末尾

CharSequence charSequence =mEtPassword.getText();

if(charSequenceinstanceofSpannable) {

Spannable spanText = (Spannable) charSequence;

Selection.setSelection(spanText,charSequence.length());

}

}



你可能感兴趣的:(Android文本输入框(EditText)切换密码的显示与隐藏)