Android 实现密码的隐藏和显示的示例
public class ChargepsdActivity extends Activity {
private EditText editText;
private CheckBox checkBox;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chargepsd);
editText = (EditText) findViewById(R.id.newpassword);
checkBox = (CheckBox) findViewById(R.id.CheckBox);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
if(isChecked){
//如果选中,显示密码
editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
}else{
//否则隐藏密码
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
}
});
}
}
本文标题:Android 实现密码的隐藏和显示的示例
本文链接:https://www.haomeiwen.com/subject/extxbktx.html
网友评论