安卓EditText显示与隐藏密码
方法一:
首先,有一个EditText和CheckedBox,在xml里面设置EditText的android:inputType="textPassword",为CheckedBox添加事件监听,
@Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
// TODO Auto-generated method stub
if (isChecked) {
mPswEdt.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
} else {
mPswEdt.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
}
}
方法二:
if (isChecked) {
mPswEdt.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
} else {
mPswEdt.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
}
}