Android 5.1.1 Error inflating class android.webkit.WebView

bugly错误日志:

android.view.InflateException:Binary XML file line #7: Error inflating class android.webkit.WebView

查找原因,分析发现崩溃发生在Android版本21和22上,直接上解决方案

import android.content.Context;import android.content.res.Configuration;import android.os.Build;import android.util.AttributeSet;import android.webkit.WebView;public class CustomWebView extends WebView {    public CustomWebView(Context context) {        super(getFixedContext(context));    }    public CustomWebView(Context context, AttributeSet attrs) {        super(getFixedContext(context), attrs);    }    public CustomWebView(Context context, AttributeSet attrs, int defStyleAttr) {        super(getFixedContext(context), attrs, defStyleAttr);    }    public static Context getFixedContext(Context context) {        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {            return context.createConfigurationContext(new Configuration());        } else {            return context;        }    }}

使用自定义的CustomWebView 替换掉原生的WebView即可解决问题;
这个问题搞了半天 特此记录一下;

更多相关文章

  1. Android(安卓)升级Android(安卓)X 所需要替换的包(二)
  2. Android中如何修改CheckBox的颜色
  3. android 工程,点击图片,在屏幕显示
  4. Android:Timer定时器
  5. 仿照利用android系统源码资源文件,修改SeekBar颜色 前景与背景
  6. android各种提示Dialog 弹出框
  7. Android(安卓)8怎么修改USB默认为MTP
  8. Android之用自定义的shape去实现shadow效果
  9. android 更改密码显示风格

随机推荐

  1. android分页处理-3
  2. android 上下抽屉拖拽+动画完美实现
  3. Android中View绘制优化二一---- 使用标签
  4. [Android Pro] ant 编译android工程
  5. android模块化开发
  6. android view holder 优化
  7. 一对一直播系统开发Android ProgressBar
  8. Android中软键盘使用总结(一)
  9. android 里使用Socket进行发送消息案例
  10. cocos2dx 移植android 报错