【问题标题】:WebView throws InflateException on android 5.0 [duplicate]WebView 在 android 5.0 上抛出 InflateException [重复]
【发布时间】:2020-02-16 16:46:48
【问题描述】:
升级到"androidx.appcompat:appcompat:1.0.2" 和"com.google.android.material:material:1.1.0-beta01" 后,WebView 在装有 Android 5.0 的设备上崩溃并抛出此异常android.view.InflateException
原因:android.view.InflateException: Binary XML file line #9: Error inflating class android.webkit.WebView
我该如何解决?
【问题讨论】:
标签:
android
android-webview
【解决方案1】:
您的 targetSdkVersion 和 buildTools 版本如何?曾经我有一个非常相似的问题。当我将 targetSdkVersion 提高到 25 并将构建工具提高到 25.0.2 时,我开始看到这个异常。
还可以尝试更新您的应用主题以从 Theme.MaterialComponents(或后代)继承。将您的 AppTheme 父级更改为 Theme.MaterialComponents。
例子
之前:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
之后:
<!-- Material application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
【解决方案2】:
正如here 所解释的,此问题是由this revision 引起的。它会影响 webview 版本
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)
}