Android中实现密码的隐藏和显示的示例
在Android开发中,需要密码的隐藏和显示,下面就和大家分享一下使用方法:
创新互联-专业网站定制、快速模板网站建设、高性价比兴国网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式兴国网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖兴国地区。费用合理售后完善,10余年实体公司更值得信赖。
xml代码:
隐藏图标代码
android:button="@null"
JAVA代码:
/**
* Created by fby on 2017/9/11.
*/
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中实现密码的隐藏和显示的示例
网页路径:http://www.jxjierui.cn/article/phocdo.html


咨询
建站咨询
