Android文本输入框(EditText)切换密码的显示与隐藏
2016-07-10 本文已影响0人
张汉
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());
}
}