使用Kotlin的WebView中的进度条

时间:2018-10-24 19:53:40

标签: android android-studio kotlin progress-bar

我正在使用此代码来显示进度条,同时要求将URL加载到WebView中,但是从Webview页开始几秒钟后,应用程序崩溃了,并且出现了错误:

  

java.lang.IllegalArgumentException:指定为非null的参数是   null:方法kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull,   参数收藏夹

  val progressBar = findViewById<ProgressBar>(R.id.prg)
    val url: String = intent.getStringExtra("targetURL") ?: ""


    webView.webViewClient = object : WebViewClient() {

        override fun onPageStarted(view: WebView, url: String, favicon: Bitmap) {
            super.onPageStarted(view, url, favicon)
            view.visibility =View.INVISIBLE
            progressBar.visibility = View.VISIBLE
        }

        override fun onPageFinished(view: WebView, url: String) {
            super.onPageFinished(view, url)
            view.visibility =View.VISIBLE
            progressBar.visibility = View.INVISIBLE
        }

    }
    webView.settings.javaScriptEnabled = true

    val settings = webView.settings
    settings.domStorageEnabled = true

    webView.loadUrl(url)

1 个答案:

答案 0 :(得分:0)

使favicon可为空。

更改

favicon: Bitmap

收件人

favicon: Bitmap?