自定義webview
/** * 處理Android 5.0 5.1 webview 閃退 */ class MyWebView : WebView { companion object{ private fun getFixedContext(context: Context): Context { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) { return context.createConfigurationContext(Configuration()) } return context } } constructor(context: Context) : super(getFixedContext(context)) constructor(context: Context, attrs: AttributeSet) : super(getFixedContext(context), attrs) constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super( getFixedContext(context), attrs, defStyleAttr ) @TargetApi(Build.VERSION_CODES.LOLLIPOP) constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super( getFixedContext(context), attrs, defStyleAttr, defStyleRes ) }
在xml中使用自己定義的webview即可