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& ...
随机推荐
- php解析url的三种方法举例
使用php解析url的三个示例. 方法一: $url="http://www.jbxue.com"; file_get_contents($url); 方法二: // CURL 方 ...
- Mac上安装brew
用过ubuntu系统的都知道,上面有一个命令apt-get 很方便可以快速的安装很多软件 特别lamp环境 都是一键安装. 在mac上也有类似的命令 brew brew用法可以访问官网地址 http ...
- Android Material Design:滑动指示选项卡android.support.design.widget.TabLayout的简单使用
该TabLayout的功用,简单的说,就是当用户在该TabLayout的选项卡子item中选择触摸时候,文字和下方的指示器横条滑动指示.这个功能就是以前APP开发常用的选项卡某一卡片被切换.选中时候的 ...
- [Solved] install Gentoo in VBox: network interface eth0 does not exist
ERROR:interface eth0 does not exist; ensure that you have loaded the correct kernel moudle for your ...
- hadoop自动安装的脚本与步骤
最近要在10几台机器上安装hadoop.对于这种繁复而重复的工作,一步步的打命令行,对于程序员来说是一件不能忍的事情.所以我就琢磨着怎么写一个脚本来自动安装hadoop. 任务: 在10几台机器上中的 ...
- 6、WPF中的特殊字符与空白
特殊字符: 小于号 < 字符实体采用<表示 大于号 > 字符实体采用>表示 &符号 字符实体采用&表示 引号"&quo ...
- Java 图形编程 二:布局管理器之顺序布局
package second; import java.awt.*; import java.awt.event.WindowAdapter; import java.awt.event.Window ...
- poll实现
struct pollfd { int fd; //当前描述符 short events; //进程关心的该描述符的事件 short revents; //返回 ...
- iOS常见问题(1)
一.storyboard连线问题 产生原因:将与storyboard关联的属性删除了,但是storyboard中还保持之前所关联的属性. 解决: 1.点击view controller 2.点击这排最 ...
- How to: Add Missing ContentPlaceHolder
In Microsoft SharePoint Server 2010, the BlueBand master page is not supported in the Search Center ...