fun showHidePass(view: View) { if(view.id == R.id.iv_login_et_pw) { if(login_et_pw.transformationMethod == PasswordTransformationMethod.getInstance()) { (view as ImageView).setImageResource(R.drawable.visibility_off) login_et_pw.transformationMethod = HideReturnsTransformationMethod.getInstance() }else { (view as ImageView).setImageResource(R.drawable.visibility_on) login_et_pw.transformationMethod = PasswordTransformationMethod.getInstance() } } }
<RelativeLayout android:id="@+id/rel_login_et_pw" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/login_et_id"> <androidx.appcompat.widget.AppCompatEditText android:id="@+id/login_et_pw" android:layout_width="match_parent" android:layout_height="50dp" android:paddingStart="10dp" android:textCursorDrawable="@drawable/cursor_color" android:hint="@string/login_hint_pw" android:textColor="@color/colorBlack" android:textColorHint="@color/colorGray" android:background="@drawable/rounded_login_edittext_bg" android:autofillHints="" android:inputType="textPassword" /> <androidx.appcompat.widget.AppCompatImageView android:id="@+id/iv_login_et_pw" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="true" android:layout_centerVertical="true" android:layout_marginEnd="10dp" android:src="@drawable/visibility_on" android:alpha=".5" android:contentDescription="@string/login" /> </RelativeLayout>