• 打勾显示输入的密码 --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());   

                  }         

               }      

            });

        }

    }

    相关知识:

    最后实现效果:

  • 相关阅读:
    今日头条Go建千亿级微服务的实践
    Apache JServ Protocol
    tomcat servlet JSP common gateway interface 公共网关接口
    pollable event-driven Flume source
    kernel.panic
    Linux查找含有某字符串的所有文件
    深入理解Linux修改hostname
    px em rem
    这跟他们的前辈在原生应用程序或印刷出版物中做的设计或多或少有点类似。
    字符串等长切分 视频字幕换行
  • 原文地址:https://www.cnblogs.com/dongweiq/p/4721314.html
Copyright © 2020-2023  润新知