Android中EditTex的密文和明文切换

来源:互联网 发布:mac c4d怎么卸载 编辑:程序博客网 时间:2024/06/02 13:06
  1. public class ShowpasswordActivity extends Activity {  
  2.       
  3.     EditText password;  
  4.     CheckBox showcheck;  

  5.     @Override  
  6.     public void onCreate(Bundle savedInstanceState) {  
  7.         super.onCreate(savedInstanceState);  
  8.         setContentView(R.layout.main);  

  9.         password  = (EditText)this.findViewById(R.id.password);  
  10.         showcheck = (CheckBox)this.findViewById(R.id.showcheck);  

  11.         //CheckBoxe的事件监听  
  12.         show.setOnCheckedChangeListener(new OnCheckedChangeListener(){  
  13.             @Override  
  14.             public void onCheckedChanged(CompoundButton buttonView,
  15.                         boolean isChecked) {  
  16.                 if(isChecked) {//设置成明文  
  17.                     password.setTransformationMethod
  18.                         (HideReturnsTransformationMethod.getInstance());  
  19.                 } else {//设置成密文  
  20.                     password.setTransformationMethod
  21.                         (PasswordTransformationMethod.getInstance());  
  22.                 }  
  23.             }  
  24.         });  
  25.     }  
  26. }  
0 0