Android EditText密码框的显示和隐藏

2022-07-30 09:29:42

最近在开发中遇到了,需要将密码框设置为显示和隐藏的需求,翻阅相关文档得到了答案,现在分享代码如下:

<EditText
            android:id="@+id/hotspotpsd_edt"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@null"
            android:inputType="textPassword"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:layout_alignParentTop="true"
            android:layout_marginRight="@dimen/dp_10"
            android:layout_toRightOf="@id/left_view"/>

2.设置显示和隐藏

display_checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){
                if(isChecked){
                    psd_edt.setTransformationMethod(HideReturnsTransformationMethod.getInstance());//显示密码}else{
                    psd_edt.setTransformationMethod(PasswordTransformationMethod.getInstance());//隐藏密码}}});
  • 作者:安卓兼职framework应用工程师
  • 原文链接:https://blog.csdn.net/baidu_41666295/article/details/105840615
    更新时间:2022-07-30 09:29:42