Android:密码显示隐藏

时间:2022-09-21 11:40:36

效果:

Android:密码显示隐藏

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

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

  1. JS控制文本框中的密码显示&sol;隐藏功能

    <html> <head> <title>[荐]JS控制文本框中的密码显示/隐藏功能_网页代码站(www.6a8a.com)</title> <s ...

  2. android密码显示和隐藏

    if (showPwd){ //设置EditText文本为可见的 password.setTransformationMethod(HideReturnsTransformationMethod.ge ...

  3. js点击 密码输入框密码显示隐藏

    很多密码框都有个眼睛标记,点击能显示密码.原理就是点击切换password为text等显示 下面上代码 <!DOCTYPE html> <html> <head> ...

  4. vue&plus;element-ui实现显示隐藏密码

    <template> <el-form :model="cuser_info" label-width="115px" label-posit ...

  5. 【Android初级】教你用两行代码实现&OpenCurlyDoubleQuote;显示&sol;隐藏密码”的效果

    Android里面要使用密码的场景是非常多的,支付宝.微信.淘宝以及各大银行APP,都跟用户的密码有关.用户的密码是极为隐私的,用户在输入时不希望密码被别人看到,所以几乎所有需要输入密码的场景下都会把 ...

  6. EditTextPreference点击后输入框显示隐藏内容,类似密码输入&lpar;转&rpar;

    http://bbs.anzhuo.cn/thread-928131-1-1.html EditTextPreference点击后输入框显示隐藏内容,类似密码输入... [复制链接]     aski ...

  7. input 显示&sol;隐藏密码

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

  8. Android上实现各种风格的隐藏菜单&comma;比如左右滑动菜单、上下滑动显示隐藏菜单

    Android上的菜单展示风格目前是各式各样的,但用的最多且体验最好的莫过于左右滑动来显示隐藏的菜单本示例实现了各种方式的菜单展示效果,只有你想不到的源码:https://github.com/Sim ...

  9. JS组件系列——显示隐藏密码切换的jQuery插件

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...

随机推荐

  1. ES5——函数,对象,方法,this

    JS由表达式和语句组成 表达式:计算出一个值,但并不进行任何操作,不改变计算机运行状态 语句:包括 声明语句,赋值语句,控制结构 函数,对象,方法,this 数组和对象:是两个非常重要的数据类型 函数 ...

  2. Linux 下 netbeans 字体抗锯齿正解

    转自:http://leenjewel.blog.163.com/blog/static/601937922010124444051/ 说来这个不难,主要是我看网上有的写的不是很明确,甚至有的写的根本 ...

  3. lua2c

    lua2c lua2c is a Lua module and utility to convert Lua 5.1 source code to C API code. http://lua-use ...

  4. iOS:等比压缩截图代码

    将一幅图片按着需要的尺寸进行等比的压缩和放大,最后再截取需要尺寸部分,不知道说清楚没,反正就那意思吧! +(UIImage *)compressImageWith:(UIImage *)image w ...

  5. Cocos-2d 坐标系及其坐标转换

    Cocos-2d中,涉及到4种坐标系: GL坐标系Cocos2D以OpenglES为图形库,所以它使用OpenglES坐标系.GL坐标系原点在屏幕左下角,x轴向右,y轴向上. 屏幕坐标系苹果的Quar ...

  6. DataSet和DataTable详解

    先构建一个结构与用户请求数据结构相同的DataTable,然后将用户的请求数据填充到构建好的DataTable中,最后将DataTable添加到DataSet中. DataTable,,DataCol ...

  7. MapList 自己封装的

    //// Source code recreated from a .class file by IntelliJ IDEA// (powered by Fernflower decompiler)/ ...

  8. js闭包绑定元素

    闭包,官方对闭包的解释是:一个拥有许多变量和绑定了这些变量的环境的表达式(通常是一个函数),因而这些变量也是该表达式的一部分.闭包的特点: 1. 作为一个函数变量的一个引用,当函数返回时,其处于激活状 ...

  9. 关于jmeter工具使用的总结

    今天总结下jmeter工具如何使用 先从最简单的说起 如何打开jemter 配置环境变量 接下来我们只要在dos窗口中输入 jmeter就能打开,这也告诉了我们配置环境变量的方便性 接下来介绍一下线程 ...

  10. spring遇到的Error applying BeanValidation relational constraints

    spring3.1+hibernate4集成测试时遇到的问题: log4j:WARN No appenders could be found for logger (org.springframewo ...