【Android】解决Vivo及5.1低版本 webView适配问题
16lz
2021-12-12
报错信息:
加载data报的异常
报错机型:
等等 基本都是vivo的
解决方案:
1.重绘WebView ,确保不会直接崩溃,退出程序
public class VivoWebView extends WebView { public VivoWebView(Context context) { super(getFixedContext(context)); } public VivoWebView(Context context, AttributeSet attrs) { super(getFixedContext(context), attrs); } public VivoWebView(Context context, AttributeSet attrs, int defStyleAttr) { super(getFixedContext(context), attrs, defStyleAttr); } // To fix Android Lollipop WebView problem create a new configuration on that Android version only private static Context getFixedContext(Context context) { if (Build.VERSION.SDK_INT == 21 || Build.VERSION.SDK_INT == 22) // Android Lollipop 5.0 & 5.1 return context.createConfigurationContext(new Configuration()); return context; }}
2.如果出现乱码——》重新设定loadData
//这一步是针对vivo 会出现乱码的情况 小米也有几率出现webView. loadData(bean.getLabelIntroduce(), "text/html; charset=UTF-8", null);; // 加载定义的代码,并设定编码格式和字符集。
加载url报的错误异常:
解决方案:
上面第一步重写WebView,以及升级"appcompat:appcompat:1.1.0"
implementation 'androidx.appcompat:appcompat:1.1.0-beta01'
更多相关文章
- android BitmapFactory的OutOfMemoryError: bitmap size exceeds
- Android(安卓)异步加载深入解析
- Android(安卓)WebView加载H5音视频自动播放、关闭Activity停止播
- Android(安卓)Studio:resource android:attr/dialogCornerRadius
- Android(安卓)4.0 Launcher2源码分析——启动过程分析
- Android横竖屏加载不同布局的适配方案
- android增加5G热点
- ArcGis for Android(安卓)shp
- Android(安卓)WebView的使用(一)