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:密码显示隐藏的更多相关文章
- JS控制文本框中的密码显示/隐藏功能
<html> <head> <title>[荐]JS控制文本框中的密码显示/隐藏功能_网页代码站(www.6a8a.com)</title> <s ...
- android密码显示和隐藏
if (showPwd){ //设置EditText文本为可见的 password.setTransformationMethod(HideReturnsTransformationMethod.ge ...
- js点击 密码输入框密码显示隐藏
很多密码框都有个眼睛标记,点击能显示密码.原理就是点击切换password为text等显示 下面上代码 <!DOCTYPE html> <html> <head> ...
- vue+element-ui实现显示隐藏密码
<template> <el-form :model="cuser_info" label-width="115px" label-posit ...
- 【Android初级】教你用两行代码实现“显示/隐藏密码”的效果
Android里面要使用密码的场景是非常多的,支付宝.微信.淘宝以及各大银行APP,都跟用户的密码有关.用户的密码是极为隐私的,用户在输入时不希望密码被别人看到,所以几乎所有需要输入密码的场景下都会把 ...
- EditTextPreference点击后输入框显示隐藏内容,类似密码输入(转)
http://bbs.anzhuo.cn/thread-928131-1-1.html EditTextPreference点击后输入框显示隐藏内容,类似密码输入... [复制链接] aski ...
- input 显示/隐藏密码
js代码: // 显示/隐藏密码 $('.open').on('click',function(){ if($("#psw").prop('type')=='password'){ ...
- Android上实现各种风格的隐藏菜单,比如左右滑动菜单、上下滑动显示隐藏菜单
Android上的菜单展示风格目前是各式各样的,但用的最多且体验最好的莫过于左右滑动来显示隐藏的菜单本示例实现了各种方式的菜单展示效果,只有你想不到的源码:https://github.com/Sim ...
- JS组件系列——显示隐藏密码切换的jQuery插件
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...
随机推荐
- Android如何设置标题栏的高度
转载自: http://blog.csdn.net/yuxiaohui78/article/details/8222993 新建一个styles.xml 1 <?xmlversion=" ...
- python学习第三天第一部分
字典 1.字典的定义和规则: 定义:{key1:value1,key2:value2} key 的定义规则:1.必须是不可变的(数字.字符串.元组):2.必须是唯一的, value的定义规则:任意类型 ...
- openerp学习笔记 跟踪状态,记录日志,发送消息
跟踪状态基础数据: kl_qingjd/kl_qingjd_data.xml <?xml version="1.0"?><openerp> <d ...
- 连续子数组的最大和/1007. Maximum Subsequence Sum (25)
题目描述 HZ偶尔会拿些专业问题来忽悠那些非计算机专业的同学.今天测试组开完会后,他又发话了:在古老的一维模式识别中,常常需要计算连续子向量的最大和,当向量全为正数的时候,问题很好解决.但是,如果向量 ...
- DB 从zl.xml中导入数据库用户名及密码等!
package com.dy.java; import java.io.FileInputStream; import java.io.FileNotFoundException; import ja ...
- 注册微信小程序
注册微信小程序 小程序是一种新的开放能力,可以在微信内被便捷地获取和传播,同时具有出色的使用体验.开发者可以根据平台提供的能力,快速地开发一个小程序. 开放内容包括: 开放注册范围:企业.政府.媒体. ...
- python学习小结9:面向对象
面向对象技术 类(Class): 用来描述具有相同的属性和方法的对象的集合.它定义了该集合中每个对象所共有的属性和方法.对象是类的实例. 类变量:类变量在整个实例化的对象中是公用的.类变量定义在类中且 ...
- Cocos2dx 截屏
void SaveScreenshot() { CCSize size = CCDirector::sharedDirector()->getWinSize(); CCRenderTexture ...
- GNOME与KDE的战争
目录1 序言2 GNOME与KDE交替发展% M" O/ h% R( b f, ~7 W' n9 V, G3 GNOME获得商业公司的支持4 KDE3.5可实现半透明和阴影效果,界面华丽. ...
- C#WinForm中在dataGridView中添加中文表头
第一步: 注意事项:(1)如果使用数据库,那么第三步的名称可以是任意的,但是不能和数据库中的列名一样,否则会报错: (2)第四步的页眉文本就是你想用的中文列名,自己定: (3)第六步尤其重要,不 ...