在Android开发中,需要密码的隐藏和显示,下面就和大家分享一下使用方法:
xml代码:
隐藏图标代码
android:button="@null"
JAVA代码:
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());
}
}
});
}
}
效果展示:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。



