Android WebView在Api 20上不显示内容

我的应用程序中有一个WebView。它可以正常工作,但在Api 20上,WebView不会显示内容。

我检查了日志并看到这些错误

I/chromium: [INFO:CONSOLE(7)] "The key "shrink-to-fit" is not recognized and ignored.",source: https://...

I/chromium: [INFO:CONSOLE(43)] "Uncaught SyntaxError: Block-scoped declarations (let,const,function,class) not yet supported outside strict mode",source: https://... (43)

我概述了一些答案,他们通常建议使用

webView.settings.useWideViewPort = true
webView.settings.loadWithOverviewMode = true

我已经实现了这些设置,但是仍然发生相同的错误。 WebView显示注意

这是我的WebView设置

/**
 * Initialize the WebView
 */
@SuppressLint("SetJavaScriptEnabled")
private fun initWebView() {

    webView.webViewClient = object : WebViewClient() {

        @RequiresApi(Build.VERSION_CODES.LOLlipoP)
        override fun shouldOverrideUrlLoading(view: WebView,request: WebResourceRequest): Boolean {

            return super.shouldOverrideUrlLoading(view,request)
        }

        override fun onPageStarted(
            view: WebView,url: String,favicon: Bitmap?) {
            showProgressDialog()
        }

        override fun onPageFinished(view: WebView,url: String) {
            hideProgressDialog()
        }

        @RequiresApi(api = Build.VERSION_CODES.M)
        override fun onReceivedError(view: WebView,request: WebResourceRequest,error: WebResourceError) {
            // Your code to do
            hideProgressDialog()
        }

        override fun onReceivedError(view: WebView,errorCode: Int,description: String,failingUrl: String) {
            // Handle the error
            hideProgressDialog()
        }

        override fun onReceivedSslError(view: WebView,handler: SslErrorHandler?,error: SslError) {
            // ignore ssl error
            if (handler != null) {
                handler.proceed()
            } else {
                super.onReceivedSslError(view,null,error)
            }
        }
    }

    webView.isHorizontalScrollBarEnabled = false
    webView.settings.javaScriptEnabled = true
    webView.settings.useWideViewPort = true
    webView.setInitialScale(1)
    webView.settings.loadWithOverviewMode = true
    context?.let { webView.setBackgroundColor(ContextCompat.getcolor(it,R.color.colordarkBlue)) }

    }

    /**
     * Load url
     */
    private fun loadPage(url: String) {
        webView.loadUrl(url)
    }

有人有主意吗?感谢您的帮助

zongjie720 回答:Android WebView在Api 20上不显示内容

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3161150.html

大家都在问