Android password visibility toggle not working with support library 25?
Asked Answered
I

4

14

I have implemented a TextInputLayout with a password field in the usual way:

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <EditText
        android:id="@+id/returning_password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/prompt_password"
        android:inputType="textPassword"
        android:maxLines="1"
        android:textSize="14sp" />

</android.support.design.widget.TextInputLayout>

This worked fine when using the Android support library up to version 24.0.2, but after switching to 25.0.1:

compile 'com.android.support:design:25.0.1'
compile 'com.android.support:support-v4:25.0.1'
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:support-vector-drawable:25.0.1'

I no longer see the password visibility toggle (a.k.a. "eye icon") in the widget. Changing to the latest version 25.1.0 does not fix this problem.

Is there anything that I missed and need to change in combination with the support library 25, or could this be an Android issue?

Indigoid answered 29/12, 2016 at 16:18 Comment(0)
I
46

Try it this way.

<android.support.design.widget.TextInputLayout
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   app:passwordToggleEnabled="true">

<EditText
    android:id="@+id/returning_password"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/prompt_password"
    android:inputType="textPassword"
    android:maxLines="1"
    android:textSize="14sp" />

</android.support.design.widget.TextInputLayout>

This might be helpful for you!!

The TextInputLayout password toggle is now disabled by default to avoid unnecessarily overwriting developer-specified end drawables. It may be manually enabled via the passwordToggleEnabled XML attribute.

Recent Support Library Revisions

Inebriety answered 29/12, 2016 at 17:36 Comment(5)
Perfect answer, thanks! That fixed it straight away, and I'll keep an eye on that link the next time the library version is updated.Indigoid
for remove password roboto default typeface use android:typeface="normal"Olin
How to achieve the same functionality with support library 23.4.0Siriasis
Sometimes the icon maybe white, so add app:passwordToggleTint="some color" for visibility.Bramblett
In Kotlin it is deprecated, should use app:endIconMode="password_toggle"Auberbach
E
6

if you use Jetpack then

add these dependencies

implementation 'com.google.android.material:material:1.0.0'

and add app:passwordToggleEnabled="true" in xml and one more thing, use inputType= textPassword and if you use rather than this then toggle button won't be shown.

Instead of using

<android.support.design.widget.TextInputLayout
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   app:passwordToggleEnabled="true">

<EditText
    android:id="@+id/returning_password"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/prompt_password"
    android:inputType="textPassword"
    android:maxLines="1"
    android:textSize="14sp" />

</android.support.design.widget.TextInputLayout>

, you need to use

<com.google.android.material.textfield.TextInputLayout
 android:layout_width="match_parent"
   android:layout_height="wrap_content"
   app:passwordToggleEnabled="true">

<EditText
    android:id="@+id/returning_password"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="@string/prompt_password"
    android:inputType="textPassword"
    android:maxLines="1"
    android:textSize="14sp" />

</com.google.android.material.textfield.TextInputLayout>
Economics answered 21/2, 2019 at 11:8 Comment(1)
Really helpful answer for those who migrated app to androidx.. ThanksMammoth
O
3

You don't need to add following:

app:passwordToggleEnabled="true"

just change your dependency to:

compile 'com.android.support:design:25.0.0'

That's the same bug I faced too while updating dependency.

Edit:

Now

app:passwordToggleEnabled="true"

is working with,

compile 'com.android.support:design:25.3.0'
Orthoclase answered 18/1, 2017 at 9:50 Comment(0)
M
1
<android.support.design.widget.TextInputLayout
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   app:passwordToggleEnabled="true">

app:passwordToggleEnabled="true">

<EditText
    android:id="@+id/edt_password"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Password"
    android:inputType="textPassword"
    android:maxLines="1"
    android:textSize="16sp" />

</android.support.design.widget.TextInputLayout>

compile 'com.android.support:design:25.0.1'

compile 'com.android.support:support-v4:25.0.1'

compile 'com.android.support:appcompat-v7:25.0.1'

compile 'com.android.support:support-vector-drawable:25.0.1'

Midgard answered 13/7, 2017 at 7:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.