0
点赞
收藏
分享

微信扫一扫

打勾显示输入的密码 --EditText与s…

律楷粑粑 2023-03-31 阅读 53


实现目标:

打勾显示输入的密码 --EditText与s…_ide

实现原理:

为CheckBox添加一个监听器事件;

打勾显示输入的密码 --EditText与s…_ide

实现的源码:

package edu.cquptzx.showPassword;
 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.EditText;
 publicclass ShowPasswordActivity extends Activity {
   private EditText edittext;
   private CheckBox checkbox; 
  
   publicvoid onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
      main);
      
      
       edittext = (EditText) findViewById(R.id.et);
       checkbox = (CheckBox) findViewById(R.id.cb);
      
      
       checkbox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()
      
          publicvoid onCheckedChanged(CompoundButton buttonView,boolean isChecked)
         
             if(checkbox.isChecked())
            
                
                 edittext.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
            
             else
            
                
                edittext.setTransformationMethod(PasswordTransformationMethod.getInstance());   
             }         
          }      
      
  
}


打勾显示输入的密码 --EditText与s…_ide

打勾显示输入的密码 --EditText与s…_ide

举报

相关推荐

0 条评论