Android:密码显示隐藏

效果:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="textPassword" >

        <requestFocus />
    </EditText>

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="显示密码" />

</LinearLayout>
package com.example.test;

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.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;

public class MainActivity extends Activity {
private TextView editText1;
private CheckBox checkBox1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);

        editText1 =(TextView) findViewById(R.id.editText1);
        checkBox1=(CheckBox) findViewById(R.id.checkBox1);

        checkBox1.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                // TODO Auto-generated method stub
                if(isChecked){
                    //如果选中,显示密码
                    editText1.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
                }else{
                    //否则隐藏密码
                    editText1.setTransformationMethod(PasswordTransformationMethod.getInstance());
                }

            }
        });
    }

}

关键是:

editText1.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
editText1.setTransformationMethod(PasswordTransformationMethod.getInstance());
时间: 2024-08-12 22:18:47

Android:密码显示隐藏的相关文章

JS控制文本框中的密码显示/隐藏功能

<html> <head> <title>[荐]JS控制文本框中的密码显示/隐藏功能_网页代码站(www.6a8a.com)</title> <style> body,input{font:menu} </style> </head> <body> <form method="POST" action="addcheck.asp" name="forms&

密码显示隐藏切换

<div class="pwd-wrap"> <input type="password" id="pwd" value="123456"> <span id="btns"> <a>显示</a> <a class="cur">隐藏</a> </span> </div> $(func

设置登录注册页面输入密码时,监听密码显示隐藏;

代码里面:在oncreate()方法里面调用:还需要先定义一个全局变量:private boolean isHidden = true; private void setchck_password() { // 设置第一次输入密码未不可见状态 login_password.setTransformationMethod(PasswordTransformationMethod .getInstance()); // 设置CheckBox监听 check_password .setOnChecke

vue中密码显示隐藏切换

html: <group> <span>设置密码</span> <x-input :type="this.registration_data.pwdType" placeholder="请填写密码" @on-change="password"></x-input> <img src="../assets/colse_eyes.png" @click="

vue+element-ui实现显示隐藏密码

<template> <el-form :model="cuser_info" label-width="115px" label-position="left" > <el-row :gutter="20"> <el-col :span="24"> <el-form-item v-if="visible2" label="

EditTextPreference点击后输入框显示隐藏内容,类似密码输入(转)

http://bbs.anzhuo.cn/thread-928131-1-1.html EditTextPreference点击后输入框显示隐藏内容,类似密码输入... [复制链接]     askilledhand ADD.幼儿园 UID 2186431 帖子 46 精华 0 积分 34 最后登录 2014-3-5 串个门 加好友 打招呼 发消息 电梯直达 1楼  发表于 2013-11-18 11:59:03 |只看该作者 |倒序浏览  一键分享 [新人报到]现在去发帖报道即可领取论坛金币哦

Android项目:输入法软键盘显示/隐藏的监听和控制,InputMethodManager用法研究

在项目开发中,用到编辑框的地方经常涉及到要监听或者控制软键盘的显示/隐藏状态.本以为这是很容易解决的一个小问题,没想到当初碰到这个问题才明白还得花点小心思才能整好.现将针对软键盘的显示/隐藏状态的监听/监控方法做一些总结,以备后用. 一.点击空白处隐藏软键盘 这是具有编辑框焦点的页面对输入法软键盘状态监听的一般需求和解决方法. 首先获得InputMethodManager:        InputMethodManager manager = (InputMethodManager) getS

checkbox选中selec才可选和显示隐藏密码

学了一个多月,感觉真正开始理解点js了,现在功能都能自己写出来不用问别人,比较开心啦! 1 checkbox选中selec才可选,否则禁用 document.addEventListener('click',function(evt){ if(evt.target.matches("#check")) { var checkbox = document.getElementById("check"); //checkbox if(checkbox.checked==

input 显示/隐藏密码

js代码: // 显示/隐藏密码 $('.open').on('click',function(){ if($("#psw").prop('type')=='password'){ $("#psw").prop('type','text'); }else{ $("#psw").prop('type','password'); } });