什么是外部超链接?
相当于是跳转到一个新的网址页面
设置setSupportMultipleWindows为false即可
webView.settings.setSupportMultipleWindows(false)
设置setSupportMultipleWindows为true
webView.settings.setSupportMultipleWindows(true)
webView.webChromeClient = object : WebChromeClient() {
override fun onCreateWindow(
view: WebView?,
isDialog: Boolean,
isUserGesture: Boolean,
resultMsg: Message?
): Boolean {
val newWebView = WebView(view!!.context)
newWebView.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(
view: WebView,
request: WebResourceRequest
): Boolean {
// 在此处进行跳转URL的处理, 一般情况下_black需要重新打开一个页面,
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
val viewIntent =
Intent(Intent.ACTION_VIEW, Uri.parse(request.url.toString()))
startActivity(viewIntent)
} else {
val viewIntent =
Intent(Intent.ACTION_VIEW, Uri.parse(request.toString()))
startActivity(viewIntent)
}
return false
}
}
val transport = resultMsg!!.obj as WebViewTransport
transport.webView = newWebView
resultMsg!!.sendToTarget()
return true
}
}
更多
浅谈WebView在新窗口浏览网页(setSupportMultipleWindows()与onCreateWindow()关系)