花弦月当木当泽txt下载:Android开发笔记(十一) — 设置EditText的显示方式
来源:百度文库 编辑:偶看新闻 时间:2024/04/30 15:43:35
通常使用EditText来作为密码输入方式,但是由于布局文件中把EditText的显示方式设置成 android:password=”true” 这样所有输入字符将变成●●●●●●的形式显示。这样虽然可以增强保密效果,但是如果想查看输入的字符怎么办?这里我们需要加一个CheckBox来控制是否显示密码。
设计思路:
1、布局加入一个EditText,把属性设置成 android:password=”true” 。
2、布局加入一个CheckBox,把属性设置成 android:checked=”false” 。
3、在程序中把CheckBox使用setOnCheckedChangeListener()设置监听器,OnCheckedChangeListener()监听器需要重写onCheckedChanged方法。判断如果选中就显示字符,不选中就使用●代替字符。
程序代码:
Java语言: EX03_22.java01 package dan.ex03_22;02
03 import android.app.Activity;
04 import android.os.Bundle;
05 import android.text.method.HideReturnsTransformationMethod;
06 import android.text.method.PasswordTransformationMethod;
07 import android.widget.CheckBox;
08 import android.widget.CompoundButton;
09 import android.widget.EditText;
10 import android.widget.TextView;
11
12 public class EX03_22 extends Activity {
13 /** Called when the activity is first created. */
14 EditText psw;
15 CheckBox select;
16
17 @Override
18 public void onCreate(Bundle savedInstanceState) {
19 super.onCreate(savedInstanceState);
20 setContentView(R.layout.main);
21 psw = (EditText) findViewById(R.id.psw);
22 select = (CheckBox) findViewById(R.id.select);
23
24 select.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {
25
26 @Override
27 public void onCheckedChanged(CompoundButton buttonView,
28 boolean isChecked) {
29 if (isChecked) {
30 psw.setTransformationMethod(HideReturnsTransformationMethod
31 .getInstance());
32 } else {
33 psw.setTransformationMethod(PasswordTransformationMethod
34 .getInstance());
35 }
36 }
37
38 });
39 }
40 }
布局代码:
XML语言: main.xml0102
04 android:background="#ffffffff"
05 android:layout_width="fill_parent"
06 android:layout_height="fill_parent"
07 xmlns:android="http://schemas.android.com/apk/res/android"
08 >
09
11 android:layout_width="wrap_content"
12 android:layout_height="wrap_content"
13 android:text="显示密码"
14 android:textColor="#ff000000"
15 android:layout_below="@+id/psw"
16 android:layout_alignParentLeft="true"
17 >
18
19
21 android:layout_width="320px"
22 android:layout_height="wrap_content"
23 android:textSize="18sp"
24 android:password="true"
25 android:layout_below="@+id/text"
26 android:layout_alignParentLeft="true"
27 >
28
29
31 android:layout_width="wrap_content"
32 android:layout_height="wrap_content"
33 android:text="请输入密码:"
34 android:textColor="#ff333333"
35 android:layout_alignParentTop="true"
36 android:layout_alignParentLeft="true"
37 >
38
39
运行效果:
Internet IntraWeb开发学习笔记(三)b.htm
paranoid android中文歌词
radiohead 的 Paranoid Android 中文翻译
请问哪里有复旦人力资源开发与管理笔记
周笔畅(笔记)歌词
初一、十一(打一字)
“十一”
家里电脑(台式机)用ADSL上网,网通的,为什么换成笔记本就上不去了?需要设置什么吗?
(笔记)的原唱是谁?
十八加十一(猜一字)
问奥数工程问题(十一)?
哪里有英语(二)笔记下载
展望未来(LOOK AHEAD) 有没有笔记?
要歌曲《笔记》(周笔畅)的乐谱
《DEATH NOTE》(死亡笔记)介绍
猜成语:儿童笔记 (粉底格)
BEC中级笔记(经济科学出版社的 )
VB对数据库开发,用户访问权限怎么设置
西部开发,对口支援。——(打一字)
二十一(打一个字)
十一银行放假吗?(工商银行)
十一寸 (打一个字)
奥数问题(二十一)?
十一比五(一个字)