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