WebView throws InflateException on android 5.0 [duplicate]

狂风中的少年 提交于 2019-12-24 18:13:25

问题


After upgrading to "androidx.appcompat:appcompat:1.0.2" and "com.google.android.material:material:1.1.0-beta01" the WebView crashes on devices with Android 5.0 and throws this exeption android.view.InflateException

Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class android.webkit.WebView

How can I fix it?


回答1:


What about your targetSdkVersion and your buildTools version? Once I had a very similar issue. I started seeing this exception when I raised the targetSdkVersion to 25 and the build tools to 25.0.2.

Also try to update your app theme to inherit from Theme.MaterialComponents (or a descendant). Change your AppTheme parent to Theme.MaterialComponents.

Example

Before:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
</style>

After:

 <!-- Material application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <!-- Customize your theme here. -->
</style>



回答2:


As explained here, this issue is due to the this revision. It affects Lollipop devices with webview version<50. Use the following code as a solution.

override fun applyOverrideConfiguration(overrideConfiguration: Configuration?) {
        if (Build.VERSION.SDK_INT in 21..25 && (resources.configuration.uiMode == AppConstants.appContext.resources.configuration.uiMode)) {
                return
        }
        super.applyOverrideConfiguration(overrideConfiguration)
}


来源:https://stackoverflow.com/questions/58472000/webview-throws-inflateexception-on-android-5-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!