使用 InputTextLayout 的密码可见性切换可能存在错误(Android 支持库)

Possible bug with Password Visibility Toggle with InputTextLayout (Android Support Library)

在 VISUAL STUDIO 2015 年使用 XAMARIN.ANDROID

添加一个带有TextInputEditText 的TextInputLayout,启用TextInputLayout 中的Password Visibility Toggle 并切换。 示例:

<android.support.design.widget.TextInputLayout
    android:id="@+id/textInputLayoutPassword"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Password"
    local:passwordToggleEnabled="true">
<android.support.design.widget.TextInputEditText
    android:id="@+id/txtPassword"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>

Android 4.4 - API 19 模拟器: 行为符合预期,密码可见性切换。

Android 5.0 - API 21 模拟器: 尝试切换时抛出异常:

04-12 15:46:40.045 E/AndroidRuntime( 1681): FATAL EXCEPTION: main 04-12 15:46:40.045 E/AndroidRuntime( 1681): Process: TestDevices.Droid.TestDevices.Droid, PID: 1681 04-12 15:46:40.045 E/AndroidRuntime( 1681): java.lang.NullPointerException: Attempt to invoke virtual method 'int java.util.ArrayList.size()' on a null object reference 04-12 15:46:40.045 E/AndroidRuntime( 1681): at android.graphics.drawable.AnimatedVectorDrawable.start(AnimatedVectorDrawable.java:423) 04-12 15:46:40.045 E/AndroidRuntime( 1681): at android.graphics.drawable.AnimatedStateListDrawable$AnimatedVectorDrawableTransition.start(AnimatedStateListDrawable.java:322) 04-12 15:46:40.045 E/AndroidRuntime( 1681): at android.graphics.drawable.AnimatedStateListDrawable.selectTransition(AnimatedStateListDrawable.java:226) 04-12 15:46:40.045 E/AndroidRuntime( 1681): at android.graphics.drawable.AnimatedStateListDrawable.onStateChange(AnimatedStateListDrawable.java:153) 04-12 15:46:40.045 E/AndroidRuntime( 1681): at android.graphics.drawable.Drawable.setState(Drawable.java:598) 04-12 15:46:40.045 E/AndroidRuntime( 1681): at android.support.v4.graphics.drawable.DrawableWrapperGingerbread.setState(DrawableWrapperGingerbread.java:145) 04-12 15:46:40.045 E/AndroidRuntime( 1681): at android.support.v4.graphics.drawable.DrawableWrapperLollipop.setState(DrawableWrapperLollipop.java:95) 04-12 15:46:40.045 E/AndroidRuntime( 1681): at android.widget.ImageView.drawableStateChanged(ImageView.java:1108) 04-12 15:46:40.045 E/AndroidRuntime( 1681): at android.support.v7.widget.AppCompatImageButton.drawableStateChanged(AppCompatImageButton.java:149) 04-12 15:46:40.045 E/AndroidRuntime( 1681): at android.view.View.refreshDrawableState(View.java:15931) 04-12 15:46:40.045 E/AndroidRuntime( 1681): at android.support.design.widget.CheckableImageButton.setChecked(CheckableImageButton.java:75) 04-12 15:46:40.045 E/AndroidRuntime( 1681): at android.support.design.widget.TextInputLayout.passwordVisibilityToggleRequested(TextInputLayout.java:1302) 04-12 15:46:40.045 E/AndroidRuntime( 1681): at android.support.design.widget.TextInputLayout.onClick(TextInputLayout.java:1076) 04-12 15:46:40.045 E/AndroidRuntime( 1681): at android.view.View.performClick(View.java:4756) 04-12 15:46:40.045 E/AndroidRuntime( 1681): at android.view.View$PerformClick.run(View.java:19749) 04-12 15:46:40.045 E/AndroidRuntime( 1681): at android.os.Handler.handleCallback(Handler.java:739) 04-12 15:46:40.045 E/AndroidRuntime( 1681): at android.os.Handler.dispatchMessage(Handler.java:95) 04-12 15:46:40.045 E/AndroidRuntime( 1681): at android.os.Looper.loop(Looper.java:135) 04-12 15:46:40.045 E/AndroidRuntime( 1681): at android.app.ActivityThread.main(ActivityThread.java:5221) 04-12 15:46:40.045 E/AndroidRuntime( 1681): at java.lang.reflect.Method.invoke(Native Method) 04-12 15:46:40.045 E/AndroidRuntime( 1681): at java.lang.reflect.Method.invoke(Method.java:372) 04-12 15:46:40.045 E/AndroidRuntime( 1681): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) 04-12 15:46:40.045 E/AndroidRuntime( 1681): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

Android 6.0 - API 23 - 模拟器和 Nexus 5 设备: 当您点击密码可见性切换时,它实际上会切换,但是图标消失了,仍然可以切换,但是图标不再可见。

这实际上是一个错误,还是我的项目有问题? 测试项目可以在这里找到:https://github.com/Digifais/XamarinAndroid_PasswordVisibilityToggleBug

似乎已在 Android 支持库 v25.3.1

中修复