Android 8.0 Oreo 在聚焦 TextInputEditText 时崩溃 [英] Android 8.0 Oreo crash on focusing TextInputEditText

查看:28
本文介绍了Android 8.0 Oreo 在聚焦 TextInputEditText 时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将我们的一些设备更新到 android 8.0 后,在关注 TextInputLayout 内的 TextInputEditText 字段时,应用程序崩溃并出现此 Exception:

After updating some of our devices to android 8.0 , upon focusing on a TextInputEditText field inside of a TextInputLayout, the app crashes with this Exception:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void
android.view.View.getBoundsOnScreen(android.graphics.Rect)' on a null object reference
at android.app.assist.AssistStructure$WindowNode.(AssistStructure.java)
at android.app.assist.AssistStructure.(AssistStructure.java)
at android.app.ActivityThread.handleRequestAssistContextExtras(ActivityThread.java:3035)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1807)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

当我们进入 android 设置 -> 系统 -> 语言 &输入 -> 高级 -> 自动填充服务 -> 无 ,然后专注于 TextInputEditText / TextInputLayout 不再崩溃.

When we go to android Settings -> System -> Languages & input -> Advanced -> Auto-fill service -> None , then focusing on the TextInputEditText / TextInputLayout no longer crashes.

我们如何在不禁用设备上新的 8.0 自动填充服务的情况下防止崩溃发生?

推荐答案

我也遇到了.事实证明,问题是由嵌套在 TextInputLayout 内的 EditText 上设置提示文本引起的.

I ran into this too. It turns out the issue was caused by setting the hint text on the EditText nested inside the TextInputLayout.

我进行了一些挖掘,并在 26.0.0 Beta 2 发行说明中找到了这个块.2017 年 6 月 Android 支持版本说明

I did some digging and found this nugget in the 26.0.0 Beta 2 release notes. Android Support Release Notes June 2017

TextInputLayout 必须在 onProvideAutofillStructure() 上设置提示

TextInputLayout must set hints on onProvideAutofillStructure()

这导致我尝试在 TextInputLayout 而不是嵌套的 EditText 上设置提示.

That led me to try setting the hint on the TextInputLayout instead of the nested EditText.

这为我解决了崩溃问题.示例:

This resolved the crashing issue for me. Example:

<android.support.design.widget.TextInputLayout
    android:id="@+id/textInputLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="Some Hint Text"
    android.support.design:hintAnimationEnabled="true"
    android.support.design:hintEnabled="true"
    android.support.design:layout_marginTop="16dp">

    <android.support.design.widget.TextInputEditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

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

我将此作为答案发布在这里 因为我把书签弄混了.很抱歉两次发布相同的答案.

I posted this as an answer here as I mixed up bookmarks. Sorry for posting the same answer twice.

这篇关于Android 8.0 Oreo 在聚焦 TextInputEditText 时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆