具体代码如下:
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()隐藏输入的字符,恢复为密码输入状态。