美文网首页
Android 实现密码的隐藏和显示的示例

Android 实现密码的隐藏和显示的示例

作者: KingWorld | 来源:发表于2020-11-06 17:48 被阅读0次
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 实现密码的隐藏和显示的示例

      本文链接:https://www.haomeiwen.com/subject/extxbktx.html