Android 8.0 Oreo crash on focusing TextInputEditText(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 时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android 8.0 Oreo 在聚焦 TextInputEditText 时崩溃
基础教程推荐
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
