zoukankan      html  css  js  c++  java
  • 3.22 打勾显示输入的密码 EditText与setTransformationMethod

    实现目标:

    实现原理:

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

    实现的源码:

    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; 

        /** Called when the activity is first created. */

        publicvoid onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);

            setContentView(R.layout.main);

            /*find the object by IDs .*/

           

            edittext = (EditText) findViewById(R.id.et);

            checkbox = (CheckBox) findViewById(R.id.cb);

           

            /* add a listener to the CheckBox */

            checkbox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener()

            {

               publicvoid onCheckedChanged(CompoundButton buttonView,boolean isChecked)

               {

                  if(checkbox.isChecked())

                  {

                      /* show the password*/

                      edittext.setTransformationMethod(HideReturnsTransformationMethod.getInstance());

                  }

                  else

                  {

                      /* hide the password */

                     edittext.setTransformationMethod(PasswordTransformationMethod.getInstance());   

                  }         

               }      

            });

        }

    }

    相关知识:

     

     

     

     

    最后实现效果:

     

     

     

  • 相关阅读:
    k8s命令
    git绿色、红色图标不显示的问题
    Git下载
    文档(PDF Word Excel PPT)转HTML前端预览方案
    腾讯云生成临时访问链接
    cron表达式的双重人格:星期和数字到底如何对应?
    Windows下nginx报错解决:CreateFile() "xxx/logs/nginx.pid" failed
    Windows命令行在任意位置启动和退出nginx
    解决博客园TinyMCE模式下内置插入代码块功能不支持Go语言的问题(两个并不完美的解决方案)
    linux系统调用system()函数详解
  • 原文地址:https://www.cnblogs.com/xilifeng/p/2645189.html
Copyright © 2011-2022 走看看