Android5.1 WebView遇坑筆記-Resources$NotFoundException


Bugly遇到異常

查找原因,分析發現崩潰發生在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'解決


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM