Unable to get current URL on click event of WebView in Android

前端 未结 2 741
青春惊慌失措
青春惊慌失措 2021-02-06 11:49
    private WebView wv;
    public void onCreate(Bundle icicle) {
      super.onCreate(icicle);
      setContentView(R.layout.infoweblinkview);

    wv=(WebView) findVie         


        
2条回答
  •  我寻月下人不归
    2021-02-06 11:58

    The method shouldOverrideUrlLoading() will be called only when a new URL is about to load in the current webview. Hence to receive an updated URL upon click inside a single webpage application you need to extend WebChromeClient class and set its instance to your webview. Whenever URL will update onProgressChanged will be called and there you will get updated URL through webview.

    webView?.webChromeClient = QuartzWebChromeClient() 
    

    Inside onProgressChanged() of QuartzWebChromeClient updated URL can be received through webview.

     private inner class QuartzWebChromeClient : WebChromeClient() {
        override fun onProgressChanged(view: WebView, newProgress: Int) {
            super.onProgressChanged(view, newProgress)
            Log.d("tag",view.url)
        }
    }
    

提交回复
热议问题