Android5.1.1系统打开包含WebView的界面崩溃闪退问题

开发集成了androidx,在Android10真机安装调试未发现任何问题,开发完成后在vivo云测平台上传apk测试后发现在

x7 Android5.1.1系统的真机上有闪退问题,看日志发现是webView问题,部分日志如下:

android.view.InflateException: Binary XML file line #338: Error inflating class android.webkit.WebView
    at android.view.LayoutInflater.createView(LayoutInflater.java:642)
    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:727)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:786)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:851)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:854)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:854)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:854)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:854)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:854)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:510)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:420)
    at com.test.www.mvp.ui.fragment.home.GoodsDetailFragment.a(GoodsDetailFragment.java:14)
......
......

可能在Android5.x的其他系统上也有这个问题,网上搜索一波找到解决方法

1.自定义WebView(使用中)

import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
import android.util.AttributeSet;
import android.webkit.WebView;
 
import androidx.annotation.RequiresApi;
 
public class LollipopFixedWebView extends WebView {
 
    public LollipopFixedWebView(Context context) {
        super(getFixedContext(context));
    }
 
    public LollipopFixedWebView(Context context, AttributeSet attrs) {
        super(getFixedContext(context), attrs);
    }
 
    public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(getFixedContext(context), attrs, defStyleAttr);
    }
 
    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(getFixedContext(context), attrs, defStyleAttr, defStyleRes);
    }
 
    public static Context getFixedContext(Context context) {
        if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT < 23) // Android Lollipop 5.0 & 5.1
            return context.createConfigurationContext(new Configuration());
        return context;
    }
}

将WebView替换为LollipopFixedWebView即可,记得xml文件和代码文件中都替换下

2.将appcompat的库版本降低(未测试)

//implementation 'androidx.appcompat:appcompat:1.1.0'
//修改为
implementation 'androidx.appcompat:appcompat:1.0.2'

over!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值