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

                  }         

               }      

            });

        }

    }

    相关知识:

    最后实现效果:

  • 相关阅读:
    3747 [POI2015]Kinoman
    1303 [CQOI2009]中位数图
    3769 [spoj 8549] BST again
    1015 [JSOI2008]星球大战starwar
    1193 [HNOI2006]马步距离
    合并Git仓库不相关历史版本解决方案
    vue-cli项目实现动态锚点定位
    jQuery加css3实现菜单栏组件(可无限添加子列表)
    JavaScript文件转成base64编码
    Ajax获取服务器响应头部信息
  • 原文地址:https://www.cnblogs.com/changkai244/p/4110388.html
Copyright © 2011-2022 走看看