
效果:
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:orIEntation="vertical" > <EditText androID:ID="@+ID/editText1" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:ems="10" androID:inputType="textPassword" > <requestFocus /> </EditText> <CheckBox androID:ID="@+ID/checkBox1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="显示密码" /></linearLayout>
package com.example.test;import androID.app.Activity;import androID.os.Bundle;import androID.text.method.HIDeReturnstransformationMethod;import androID.text.method.PasswordtransformationMethod;import androID.Widget.CheckBox;import androID.Widget.Compoundbutton;import androID.Widget.Compoundbutton.OnCheckedchangelistener;import androID.Widget.TextVIEw;public class MainActivity extends Activity {private TextVIEw editText1;private CheckBox checkBox1; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.test); editText1 =(TextVIEw) findVIEwByID(R.ID.editText1); checkBox1=(CheckBox) findVIEwByID(R.ID.checkBox1); checkBox1.setonCheckedchangelistener(new OnCheckedchangelistener() { @OverrIDe public voID onCheckedChanged(Compoundbutton buttonVIEw,boolean isChecked) { // Todo auto-generated method stub if(isChecked){ //如果选中,显示密码 editText1.settransformationMethod(HIDeReturnstransformationMethod.getInstance()); }else{ //否则隐藏密码 editText1.settransformationMethod(PasswordtransformationMethod.getInstance()); } } }); }}关键是:
editText1.settransformationMethod(HIDeReturnstransformationMethod.getInstance());editText1.settransformationMethod(PasswordtransformationMethod.getInstance());
以上所述是小编给大家介绍的AndroID 密码 显示与隐藏功能实例,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程小技巧网站的支持!
总结以上是内存溢出为你收集整理的Android 密码 显示与隐藏功能实例全部内容,希望文章能够帮你解决Android 密码 显示与隐藏功能实例所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)