设置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 }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值