简体   繁体   English

Android 密码可见性切换不适用于支持库 25?

[英]Android password visibility toggle not working with support library 25?

I have implemented a TextInputLayout with a password field in the usual way:我以通常的方式实现了一个带有密码字段的 TextInputLayout :

<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:这在使用 Android 支持库到版本 24.0.2 时运行良好,但在切换到 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 (aka "eye icon") in the widget.我不再在小部件中看到密码可见性切换(又名“眼睛图标”)。 Changing to the latest version 25.1.0 does not fix this problem.更改为最新版本 25.1.0 并不能解决此问题。

Is there anything that I missed and need to change in combination with the support library 25, or could this be an Android issue?有什么我遗漏的地方需要结合支持库 25 进行更改,或者这可能是 Android 问题吗?

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.现在默认禁用 TextInputLayout 密码切换,以避免不必要地覆盖开发人员指定的最终可绘制对象。 It may be manually enabled via the passwordToggleEnabled XML attribute.它可以通过 passwordToggleEnabled XML 属性手动启用。

Recent Support Library Revisions 最近的支持库修订

if you use Jetpack then如果你使用 Jetpack 那么

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.并在 xml 中添加app:passwordToggleEnabled="true"和一件事,使用inputType= textPassword ,如果您使用而不是这个,则不会显示切换按钮。

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>

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'
<android.support.design.widget.TextInputLayout
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   app:passwordToggleEnabled="true">

app:passwordToggleEnabled="true">应用程序: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'编译'com.android.support:design:25.0.1'

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

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM