前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Android 密码的隐藏和显示

Android 密码的隐藏和显示

作者头像
网罗开发
发布2021-01-29 17:15:35
2.1K0
发布2021-01-29 17:15:35
举报
文章被收录于专栏:网罗开发

在Android开发中,需要密码的隐藏和显示,下面就和大家分享一下使用方法: xml代码:

代码语言:javascript
复制
        <LinearLayout
           android:layout_width="match_parent"
           android:layout_height="50dp"
           android:background="@color/white"
           android:orientation="horizontal" >           <TextView
               android:layout_width="wrap_content"
               android:layout_height="match_parent"
               android:text="新密码"
               android:textColor="@color/black"
               android:textSize="18dp"
               android:gravity="center_vertical"
               android:layout_marginLeft="15dp"/>           <EditText
               android:id="@+id/newpassword"
               android:layout_width="0dp"
               android:layout_weight="1"
               android:layout_height="match_parent"
               android:layout_gravity="center_vertical"
               android:layout_marginLeft="10dp"
               android:inputType="textPassword"
               android:hint="请设置登录密码"
               android:background="@null"/>           <CheckBox
               android:id="@+id/CheckBox"
               android:layout_width="wrap_content"
               android:layout_height="match_parent"
               android:layout_marginRight="15dp"
               android:textSize="16dp"
               android:text="显示"
               />       </LinearLayout>
隐藏图标代码
代码语言:javascript
复制
android:button="@null"

JAVA代码:

代码语言:javascript
复制
/**
* Created by fby on 2017/9/11.
*/public class ChargepsdActivity extends Activity {   private EditText editText;
   private CheckBox checkBox;   @Override
   protected void onCreate(@Nullable Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_chargepsd);       editText = (EditText) findViewById(R.id.newpassword);
       checkBox = (CheckBox) findViewById(R.id.CheckBox);       checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
           @Override
           public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {               if(isChecked){
                   //如果选中,显示密码
                   editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
               }else{
                   //否则隐藏密码
                   editText.setTransformationMethod(PasswordTransformationMethod.getInstance());               }           }
       });   }
}

效果展示:

隐藏

显示

Android开发~获取验证码倒计时实现

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2017-10-19,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 网罗开发 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 隐藏图标代码
相关产品与服务
验证码
腾讯云新一代行为验证码(Captcha),基于十道安全栅栏, 为网页、App、小程序开发者打造立体、全面的人机验证。最大程度保护注册登录、活动秒杀、点赞发帖、数据保护等各大场景下业务安全的同时,提供更精细化的用户体验。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档