首页 > 移动平台 > 详细

Android 5.1 5.2 webview 闪退问题

时间:2019-11-20 14:51:08      阅读:427      评论:0      收藏:0      [点我收藏+]

自定义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即可

Android 5.1 5.2 webview 闪退问题

原文:https://www.cnblogs.com/rchao/p/11897684.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!