方法一:重写webview构造方法
public class MyWebView 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);
}
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;
}
}
方法二:修改build.gradle appcompat依赖版本
dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0-beta01'
}