android editText输入框输入密码的显示与隐藏

      

使用环境:

              有需要输入密码时使用

使用方法:

<EditText
                android:id="@+id/pwd"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_marginLeft="@dimen/eight"
                android:layout_weight="1"
                android:background="@null"
                android:drawablePadding="8dp"
                android:hint="@string/input_pwd"
                android:inputType="textPassword"
                android:maxLength="13"
                android:maxLines="1"
                android:text="111111"
                android:textColor="@color/tv_1"
                android:textColorHint="@color/tv_3"
                android:textSize="@dimen/textsize15" />

  代码调用:

   //lock = true;
                if (lock) {
                    lock = false;
                    //设置密码可见
                    binding.pwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
                    //设置对应的输入框可见图片
                    binding.ivModuleYear.setImageResource(R.drawable.years_y);
                }else{
                    lock = true;
                    binding.pwd.setTransformationMethod(PasswordTransformationMethod.getInstance());
                    binding.ivModuleYear.setImageResource(R.drawable.year_n);
                }

猜你喜欢

转载自blog.csdn.net/csdn_loveQingQing/article/details/84996425