在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):致命异常:主要 04-12 15:46:40.045 E / AndroidRuntime(1681):进程:TestDevices.Droid.TestDevices.Droid,PID:1681 04-12 15:46:40.045 E / AndroidRuntime(1681):java.lang.NullPointerException:尝试调用虚方法&#39; int java.util.ArrayList.size()&#39;在null对象引用上 04-12 15:46:40.045 E / AndroidRuntime(1681):在android.graphics.drawable.AnimatedVectorDrawable.start(AnimatedVectorDrawable.java:423) 04-12 15:46:40.045 E / AndroidRuntime(1681):在android.graphics.drawable.AnimatedStateListDrawable $ AnimatedVectorDrawableTransition.start(AnimatedStateListDrawable.java:322) 04-12 15:46:40.045 E / AndroidRuntime(1681):在android.graphics.drawable.AnimatedStateListDrawable.selectTransition(AnimatedStateListDrawable.java:226) 04-12 15:46:40.045 E / AndroidRuntime(1681):在android.graphics.drawable.AnimatedStateListDrawable.onStateChange(AnimatedStateListDrawable.java:153) 04-12 15:46:40.045 E / AndroidRuntime(1681):在android.graphics.drawable.Drawable.setState(Drawable.java:598) 04-12 15:46:40.045 E / AndroidRuntime(1681):在android.support.v4.graphics.drawable.DrawableWrapperGingerbread.setState(DrawableWrapperGingerbread.java:145) 04-12 15:46:40.045 E / AndroidRuntime(1681):在android.support.v4.graphics.drawable.DrawableWrapperLollipop.setState(DrawableWrapperLollipop.java:95) 04-12 15:46:40.045 E / AndroidRuntime(1681):在android.widget.ImageView.drawableStateChanged(ImageView.java:1108) 04-12 15:46:40.045 E / AndroidRuntime(1681):在android.support.v7.widget.AppCompatImageButton.drawableStateChanged(AppCompatImageButton.java:149) 04-12 15:46:40.045 E / AndroidRuntime(1681):在android.view.View.refreshDrawableState(View.java:15931) 04-12 15:46:40.045 E / AndroidRuntime(1681):在android.support.design.widget.CheckableImageButton.setChecked(CheckableImageButton.java:75) 04-12 15:46:40.045 E / AndroidRuntime(1681):在android.support.design.widget.TextInputLayout.passwordVisibilityToggleRequested(TextInputLayout.java:1302) 04-12 15:46:40.045 E / AndroidRuntime(1681):在android.support.design.widget.TextInputLayout $ 4.onClick(TextInputLayout.java:1076) 04-12 15:46:40.045 E / AndroidRuntime(1681):在android.view.View.performClick(View.java:4756) 04-12 15:46:40.045 E / AndroidRuntime(1681):在android.view.View $ PerformClick.run(View.java:19749) 04-12 15:46:40.045 E / AndroidRuntime(1681):在android.os.Handler.handleCallback(Handler.java:739) 04-12 15:46:40.045 E / AndroidRuntime(1681):在android.os.Handler.dispatchMessage(Handler.java:95) 04-12 15:46:40.045 E / AndroidRuntime(1681):在android.os.Looper.loop(Looper.java:135) 04-12 15:46:40.045 E / AndroidRuntime(1681):在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
答案 0 :(得分:0)
似乎已在Android支持库v25.3.1中修复