Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show or Hide text using password toggle

I am doing show or hide password using below code

pwdLayout.setEndIconMode(TextInputLayout.END_ICON_PASSWORD_TOGGLE);

I am able to achieve show or hide password. But eye icon with cross sign is showing password and without cross sign is hiding password. I need to reverse this logic how to do this?

like image 281
Sandhiya Avatar asked Sep 11 '20 07:09

Sandhiya


People also ask

How do I hide text in password field?

<input type = "password" > Thus the entered characters are masked or hidden. To make a textbox that can hide the entered characters, the type attribute of <input> element should be set to "password."

How do I toggle visibility password?

In order to toggle the visibility of the password, one needs to follow the below-described steps: Step 1: Create an input element with a password field that will take input in the password form. Step 2: Add an icon within the input element on which the user can click to toggle the visibility of the password.

How do you toggle show and hide password multiple fields in react?

To show or hide the password in the input field in Reactjs, the basic idea is to change the input tag's type attribute to text from password and vice versa on clicking the "Show password" button or an appropriate button of your own.


1 Answers

Starting from the 1.2.0 this is the default behavior:

enter image description here enter image description here

If you want to reverse the icon you can use something like:

<com.google.android.material.textfield.TextInputLayout
    app:endIconDrawable="@drawable/custom_password_eye"

with:

<animated-selector xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:ignore="NewApi">

    <item
        android:id="@+id/visible"
        android:drawable="@drawable/design_ic_visibility"
        android:state_checked="true"/>

    <item
        android:id="@+id/masked"
        android:drawable="@drawable/design_ic_visibility_off"/>

    <transition
        android:drawable="@drawable/avd_show_password"
        android:fromId="@id/masked"
        android:toId="@id/visible"/>

    <transition
        android:drawable="@drawable/avd_hide_password"
        android:fromId="@id/visible"
        android:toId="@id/masked"/>

</animated-selector>

enter image description here enter image description here

like image 153
Gabriele Mariotti Avatar answered Oct 10 '22 00:10

Gabriele Mariotti