zoukankan      html  css  js  c++  java
  • Android_EditText 打勾显示输入的密码 --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());   

                  }         

               }      

            });

        }

    }

    相关知识:

    最后实现效果:

  • 相关阅读:
    Flink基础(57):FLINK-SQL函数(20) 内置函数(15)日期函数(二)
    Flink基础(56):FLINK-SQL函数(19)内置函数(14)字符串函数(五)
    位示图算法实现大数据的存储
    位示图算法实现大数据的存储
    JobTracker作业启动过程分析
    mysql 查询优化~ 分页优化讲解
    mysql 原理~ index的详解
    指纹识别开发1.0
    java8 base64编码和解码
    Cow Bowling POJ
  • 原文地址:https://www.cnblogs.com/changkai244/p/4110388.html
Copyright © 2011-2022 走看看