具体代码如下:
final EditText et = (EditText)findViewById(R.id.tv);
CheckBox cBox = (CheckBox)findViewById(R.id.box);
cBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
et.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
}else {
et.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
}
});HideReturnsTransformationMethod.getInstance()正常显示所输入的密码字符;
PasswordTransformationMethod.getInstance()隐藏输入的字符,恢复为密码输入状态。
本文介绍了一个简单的Android应用功能实现——通过CheckBox控制EditText中密码的显示与隐藏状态。当CheckBox被选中时,密码将以明文形式展示;反之,则以密码形式显示。
953

被折叠的 条评论
为什么被折叠?



