vivo x7 5.1.1 WebView崩溃

2,132 阅读1分钟

项目中发现,直接使用WebView,会出现崩溃。

解决方案如下:

    public XWebView(Context context) {
        super(getFixdsContext(context));
    }

    public XWebView(Context context, AttributeSet attrs) {
        super(getFixdsContext(context), attrs);
    }

    public XWebView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(getFixdsContext(context), attrs, defStyleAttr);
    }

    private static Context getFixdsContext(Context context) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            return context.createConfigurationContext(new Configuration());
        } else {
            return context;
        }
    }