Android5.1 WebView遇坑笔记-Resources$NotFoundException

老子叫甜甜 提交于 2020-01-16 06:07:04

查找原因,分析发现崩溃发生在Android版本21和22上,在网上查找资料发现下面解决方案

使用自定义WebView替换原生自带WebView解决

package com.test.test;

import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
import android.util.AttributeSet;
import android.webkit.WebView;

public class CustomWebView extends WebView {
    public CustomWebView(Context context) {
        super(getFixedContext(context));
    }

    public CustomWebView(Context context, AttributeSet attrs) {
        super(getFixedContext(context), attrs);
    }

    public CustomWebView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(getFixedContext(context), attrs, defStyleAttr);
    }

    public static Context getFixedContext(Context context) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
            return context.createConfigurationContext(new Configuration());
        } else {
            return context;
        }
    }
}
替换后WebView能打开了,可是又遇到了新的问题,WebView读取html select下拉框标签出现崩溃

解决方案,继续使用原生WebView

由版本implementation 'androidx.appcompat:appcompat:1.1.0'版本

修改版本至implementation 'androidx.appcompat:appcompat:1.0.2'解决

 

本文转自:https://www.cnblogs.com/eagle816/p/11951237.html

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