Android开发:重写WebView处理Android 5.0系统报错问题

开发语言:Java
开发生态:Android

解决方案
重写WebView(LollipopFixedWebView.java),在xml文件中使用。

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

  private static Context getFixedContext(Context context) {
    // Android Lollipop 5.0 & 5.1
    if (Build.VERSION.SDK_INT >= 21 && Build.VERSION.SDK_INT < 23) 
      return context.createConfigurationContext(new Configuration());
    return context;
  }
}

在xml文件中使用

<com.***.***.LollipopFixedWebView
    android:id="@+id/webView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。