zoukankan      html  css  js  c++  java
  • 设置登录注册页面输入密码时,监听密码显示隐藏;

    代码里面;在oncreate()方法里面调用;还需要先定义一个全局变量:private boolean isHidden = true;

    private void setchck_password() {
            // 设置第一次输入密码未不可见状态
            login_password.setTransformationMethod(PasswordTransformationMethod
                    .getInstance());
            // 设置CheckBox监听
            check_password
                    .setOnCheckedChangeListener(new OnCheckedChangeListener() {
    
                        public void onCheckedChanged(CompoundButton arg0,
                                boolean arg1) {
                            //
                            isHidden = arg1;
    
                            if (isHidden) {
                                // 设置EditText文本为可见的
                                login_password
                                        .setTransformationMethod(HideReturnsTransformationMethod
                                                .getInstance());
                            } else {
                                // 设置EditText文本为隐藏的
                                login_password
                                        .setTransformationMethod(PasswordTransformationMethod
                                                .getInstance());
                            }
                            isHidden = !isHidden;
                            login_password.postInvalidate();
                            // 切换后将EditText光标置于末尾
                            CharSequence charSequence = login_password.getText();
                            if (charSequence instanceof Spannable) {
                                Spannable spanText = (Spannable) charSequence;
                                Selection.setSelection(spanText,
                                        charSequence.length());
                            }
    
                        }
                    });
    
        }

    在xml里面的布局;

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/logging_image"
        android:orientation="vertical"
        tools:context=".LoggingActivity" >
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="right" >
    
            <TextView
                android:id="@+id/back"
                android:layout_width="50px"
                android:layout_height="50px"
                android:layout_margin="20px"
                android:background="@drawable/bns_search_del"
                android:textColor="#fff" />
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal" >
    
            <ImageView
                android:id="@+id/image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/icons" />
        </LinearLayout>
    
        <LinearLayout
            android:id="@+id/a"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/image"
            android:layout_margin="40px" >
    
            <ImageView
                android:id="@+id/image_phone1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/contact_person" />
    
            <EditText
                android:id="@+id/login_phone"
                android:layout_width="0px"
                android:layout_height="wrap_content"
                android:layout_weight="10"
                android:background="#fff"
                android:hint="请输入手机号"
                android:padding="15px" />
        </LinearLayout>
    
        <LinearLayout
            android:id="@+id/c"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="40px" >
    
            <ImageView
                android:id="@+id/image_phone2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/contact_person" />
    
            <EditText
                android:id="@+id/code"
                android:layout_width="0px"
                android:layout_height="wrap_content"
                android:layout_weight="10"
                android:background="#fff"
                android:hint="请输入用户名"
                android:padding="15px" />
        </LinearLayout>
    
        <LinearLayout
            android:id="@+id/b"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="40px" >
    
            <ImageView
                android:id="@+id/image_phone3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/contact_person" />
    
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="10" >
    
                <EditText
                    android:id="@+id/login_password"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="#fff"
                    android:hint="请输入密码"
                    android:inputType="textPassword"
                    android:padding="15px" />
    
                <CheckBox
                    android:id="@+id/check_password"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_centerVertical="true"
                    android:layout_marginRight="15dp"
                    android:background="@drawable/logging_checkbox"
                    android:button="@null" />
            </RelativeLayout>
        </LinearLayout>
    
        <Button
            android:id="@+id/login_button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="40px"
            android:background="#f90"
            android:text="注册" />
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20px"
            android:gravity="right"
            android:text="注册即视为同意Help_me《隐私条款》"
            android:textColor="#fff"
            android:textSize="20px" />
    
    </LinearLayout>
  • 相关阅读:
    python 查看安装包列表
    Centos7 linux下通过源码安装redis以及使用
    python 安装pip
    python3.7.2 pip 出现locations that require TLS/SSL异常处理方法
    Xshell报错“The remote SSH server rejected X11 forwarding request.”
    ERROR: child process failed, exited with error number 100
    centos7 (ifconfig不能使用) -bash: ifconfig: command not found
    gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now
    Centos7 安装python3.7.2
    Python安装常见问题:zipimport.ZipImportError: can't decompress data; zlib not available 解决办法
  • 原文地址:https://www.cnblogs.com/zhengyanyan/p/5497471.html
Copyright © 2011-2022 走看看