Android 5.0 5.1 webview 闪退问题


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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM