什么是外部超链接?
相当于是跳转到一个新的网址页面
解决方案选择:
1.在WebView内部中打开外部超链接
设置setSupportMultipleWindows为false即可
webView.settings.setSupportMultipleWindows(false)
2.打开系统浏览器打开新页面
设置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 WebViewTransporttransport.webView = newWebViewresultMsg!!.sendToTarget()return true}}
更多
浅谈WebView在新窗口浏览网页(setSupportMultipleWindows()与onCreateWindow()关系)
webview某些超链接点击无响应的问题
安卓WebView详解 (四)–WebSettings的API及说明