我一直在尝试使用此网址https://andela.com/alc加载网页,但是结果全为空白,但是当我尝试其他网址(例如“ https://codingjuction.com”)时,该网页将在webview中呈现。问题吗?
我尝试过使用webview客户端,但这无济于事
Webview客户端类
class MyWebViewClient internal constructor(private val activity: Activity) : WebViewClient() {
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
val url = request!!.url.host
view?.loadUrl(url)
return true
}
override fun shouldOverrideUrlLoading(webView: WebView, url: String): Boolean {
webView?.loadUrl(url)
return true
}
override fun onReceivedError(view: WebView, request: WebResourceRequest, error: WebResourceError) {
Toast.makeText(activity, "Got Error! $error", Toast.LENGTH_SHORT).show()
}
}
在oncreate中调用loadUrl
webView = findViewById(R.id.andela_info)
if (webView != null) {
val webSettings = webView!!.settings
webSettings.javaScriptEnabled = true
webSettings.builtInZoomControls = true
webView!!.webViewClient = MyWebViewClient(this)
webView!!.webChromeClient = WebChromeClient(this)
webView!!.loadUrl("https://andela.com/alc")
}
我希望页面(https://andela.com/alc)在Webview中呈现