Make passwords visible

Without further ado, this is an Activity that uses Kotlin:

var isHideFirst = true login_img_eye.setOnClickListener { if (isHideFirst === true) { Login_img_eye. SetImageResource (R.d rawable. Kejian) / / ciphertext val method1. = HideReturnsTransformationMethod getInstance () login_et_password.setTransformationMethod(method1) isHideFirst = false } else { Login_img_eye.setimageresource (r.drawable.kejian2) // Ciphertext val method: TransformationMethod = PasswordTransformationMethod.getInstance() login_et_password.setTransformationMethod(method) IsHideFirst = true} val index: Int = login_et_password.getText().toString().length login_et_password.setSelection(index) }Copy the code

Layout:

<EditText android:id="@+id/login_et_password" android:layout_width="300dp" android:layout_height="50dp" Android :layout_margin="20dp" Android :background="@drawable/item_corners" Android :hint=" Please enter password "Android :padding=" 10DP" Android :inputType="textPassword" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@id/login_et_phone" /> <ImageView android:id="@+id/login_img_eye" android:layout_width="30dp" android:layout_height="30dp" android:layout_marginLeft="220dp" android:src="@drawable/dlqq" app:layout_constraintBottom_toBottomOf="@id/login_et_password" app:layout_constraintLeft_toLeftOf="@id/login_et_password" app:layout_constraintRight_toRightOf="@id/login_et_password" app:layout_constraintTop_toTopOf="@id/login_et_password" />Copy the code