【Android】解決Vivo及5.1低版本 webView適配問題

報錯信息:

加載data報的異常

 

報錯機型

等等 基本都是vivo的

解決方案:

1.重繪WebView ,確保不會直接崩潰,退出程序

 

public class VivoWebView extends WebView {

    public VivoWebView(Context context) {
        super(getFixedContext(context));
    }

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

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

    // To fix Android Lollipop WebView problem create a new configuration on that Android version only
    private static Context getFixedContext(Context context) {
        if (Build.VERSION.SDK_INT == 21 || Build.VERSION.SDK_INT == 22) // Android Lollipop 5.0 & 5.1
            return context.createConfigurationContext(new Configuration());
        return context;
    }
}

2.如果出現亂碼——》重新設定loadData

//這一步是針對vivo 會出現亂碼的情況  小米也有機率出現
webView. loadData(bean.getLabelIntroduce(), "text/html; charset=UTF-8", null);; // 加載定義的代碼,並設定編碼格式和字符集。

 

加載url報的錯誤異常:

 

解決方案:

上面第一步重寫WebView,以及升級"appcompat:appcompat:1.1.0"

implementation 'androidx.appcompat:appcompat:1.1.0-beta01'

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章