WebView Crash on Android 5-5.1 (API 21-22)

重写一下 WebView。

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);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(getFixedContext(context), attrs, defStyleAttr, defStyleRes);
    }

    public LollipopFixedWebView(Context context, AttributeSet attrs, int defStyleAttr, boolean privateBrowsing) {
        super(getFixedContext(context), attrs, defStyleAttr, privateBrowsing);
    }

    public static Context getFixedContext(Context context) {
        return context.createConfigurationContext(new Configuration());
    }
}

参考: https://stackoverflow.com/questions/41025200/android-view-inflateexception-error-inflating-class-android-webkit-webview

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • AndroidWebView 一、简介 WebView在Android平台上是一个特殊的View, 基于webki...
    斌林诚上阅读 1,960评论 0 5
  • [TOC] 概述 Webkit是一个开源浏览器项目,其中,对Android开发者来说,或多或少的都有些接触。 在应...
    SIM卡丢失阅读 8,354评论 2 16
  • 前言 由于业务需求更新迭代快,发布新版本的App需要时间,即使发布了也不能保证用户立即更新,因此越来越多的app使...
    JeremySun0823阅读 2,891评论 1 10
  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 11,148评论 1 32
  • 年纪再小一点的时候,很讨厌周围的人抽烟,感觉像毒气一样闻到就要死了。新闻舆论也整天整夜说抽烟有害身体健康,会得肺癌...
    斯内克尔阅读 286评论 1 0