Android5.x中WebView报错 Error inflating class android.webkit.WebView

在Android5.x版本中会报以下的错误

android.view.InflateException: Binary XML file line #24: Error inflating class android.webkit.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) {
        if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT < 23) // Android Lollipop 5.0 & 5.1
            return context.createConfigurationContext(new Configuration());
        return context;
    }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 此文献给一或者众多可怜的不可公开的一女生,望上帝保佑你,愿少司命庇佑你。 花儿为谁开 一生只此四季 春风夏雨秋霜冬...
    青莲师兄阅读 218评论 0 3
  • 坐船来的?走路来的? 喝茶去!
    享受阅读 243评论 0 1
  • 四 但凡能用钱解决的事,都不算什么事。窦十三一向这样认为。 玲珑锁出自皇城,出自大唐已故玉雕师江夜雨。鳏独江夜雨有...
    铭玥咏全阅读 203评论 0 0
  • 要穿好外套,是不是需要有漂亮的内搭呢?当然,内搭款式丰富多样,不过今天,我想来介绍一件人人都能穿的、百搭的...
    穿搭云学堂阅读 452评论 0 1