设置TextView的密码效果以及跑马灯效果

密码效果以及跑马灯效果:

 

xml:

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="vertical" >
 6 
 7     <CheckBox
 8         android:id="@+id/chk_01"
 9         android:layout_width="match_parent"
10         android:layout_height="wrap_content"
11         android:text="保存账号及密码" />
12 
13     <EditText
14         android:id="@+id/et_logName"
15         android:layout_width="match_parent"
16         android:layout_height="wrap_content"
17         android:hint="Please input your LogName" />
18 
19     <EditText
20         android:id="@+id/et_logPassword"
21         android:layout_width="match_parent"
22         android:layout_height="wrap_content"
23         android:hint="Please input your PassWord" />
24 
25     <Button
26         android:id="@+id/btn_save"
27         android:layout_width="match_parent"
28         android:layout_height="wrap_content"
29         android:text="保存" />
30 
31     <com.wyl.fragementtest.MaqueeText
32         android:id="@+id/tv_01_pmd"
33         android:layout_width="match_parent"
34         android:layout_height="wrap_content"
35         android:ellipsize="marquee"
36         android:focusable="true"
37         android:focusableInTouchMode="true"
38         android:singleLine="true"
39         android:text="将文本框的内容以明文显示:editText1.setTransformationMethod(HideReturnsTransformationMethod.getInstance());" />
40 
41     <com.wyl.fragementtest.MaqueeText
42         android:layout_width="wrap_content"
43         android:layout_height="wrap_content"
44         android:ellipsize="marquee"
45         android:focusable="true"
46         android:focusableInTouchMode="true"
47         android:marqueeRepeatLimit="marquee_forever"
48         android:singleLine="true"
49         android:text="editText1.setTransformationMethod(PasswordTransformationMethod.getInstance());//将文本框的内容以密码显示" />
50 
51     <com.wyl.fragementtest.MaqueeText
52         android:layout_width="wrap_content"
53         android:layout_height="wrap_content"
54         android:ellipsize="marquee"
55         android:focusable="true"
56         android:focusableInTouchMode="true"
57         android:marqueeRepeatLimit="marquee_forever"
58         android:singleLine="false"
59         android:text="将文本框的内容以密码显示:editText1.setTransformationMethod(PasswordTransformationMethod.getInstance());将文本框的内容以明文显示:editText1.setTransformationMethod(HideReturnsTransformationMethod.getInstance());" />
60 
61 </LinearLayout>

MaqueeText.java

 1 package com.wyl.fragementtest;
 2 
 3 import android.content.Context;
 4 import android.util.AttributeSet;
 5 import android.widget.TextView;
 6 
 7 public class MaqueeText extends TextView{
 8 
 9     public MaqueeText(Context context) {
10         super(context);
11         // TODO Auto-generated constructor stub
12     }
13 
14     public MaqueeText(Context context, AttributeSet attrs, int defStyle) {
15         super(context, attrs, defStyle);
16         // TODO Auto-generated constructor stub
17     }
18 
19     public MaqueeText(Context context, AttributeSet attrs) {
20         super(context, attrs);
21         // TODO Auto-generated constructor stub
22     }
23     @Override
24     public boolean isFocused() {
25         //返回true,表示MaqueeText控件活的焦点,只有获得了焦点textView才会有跑马灯效果
26         return true;
27     }
28 }

 

posted @ 2015-10-27 21:35  Sunor  阅读(723)  评论(0编辑  收藏  举报