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());   

                  }         

               }      

            });

        }

    }

    相关知识:

     

     

     

     

    最后实现效果:

     

     

     

  • 相关阅读:
    ubuntu 启动 重启 停止 apache
    /usr/bin/env: php: No such file or directory 【xunsearch demo项目体验】【已解决】
    安装mezzanine时报:storing debug log for failure【已解决】
    redhat 安装 setuptools【成功】
    SnowNLP:一个处理中文文本的 Python 类库[转]
    Android 了解1G 2G 3G 知识
    Android-体系架构
    Android-bindService远程服务(Aidl)-初步
    Android-SDCard外部存储文件读写
    Android-文件模式
  • 原文地址:https://www.cnblogs.com/xilifeng/p/2645189.html
Copyright © 2011-2022 走看看