Android password visibility toggle not working with support library 25?

旧城冷巷雨未停 提交于 2019-12-21 03:58:08

问题


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?


回答1:


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




回答2:


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'



回答3:


<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'




回答4:


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.



来源:https://stackoverflow.com/questions/41383424/android-password-visibility-toggle-not-working-with-support-library-25

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!