美文网首页Androidandnroid
Android5.x中WebView报错 Error infl

Android5.x中WebView报错 Error infl

作者: 关木山_0926 | 来源:发表于2019-11-27 17:40 被阅读0次

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

    相关文章

      网友评论

        本文标题:Android5.x中WebView报错 Error infl

        本文链接:https://www.haomeiwen.com/subject/bxqmwctx.html