Android中实现密码的隐藏和显示的示例

Android中实现密码的隐藏和显示的示例,第1张

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

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

xml代码:

    <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>

隐藏图标代码

androID:button="@null"

JAVA代码:

/** * 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中实现密码的隐藏和显示的示例全部内容,希望文章能够帮你解决Android中实现密码的隐藏和显示的示例所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1144503.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存