
查找原因,分析发现崩溃发生在Android版本21和22上,在网上查找资料发现下面解决方案
使用自定义WebView替换原生自带WebView解决
package com.test.test;
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;
}
}
}
替换后WebView能打开了,可是又遇到了新的问题,WebView读取html select下拉框标签出现崩溃
解决方案,继续使用原生WebView
由版本implementation 'androidx.appcompat:appcompat:1.1.0'版本
修改版本至implementation 'androidx.appcompat:appcompat:1.0.2'解决
针对Android版本21和22上的WebView崩溃问题,通过自定义WebView替代原生组件,但遇到html select标签处理的新问题。最终,将appcompat库版本回滚到1.0.2解决。
1192

被折叠的 条评论
为什么被折叠?



