2011-10-19 55 views
1

如何在WebView中獲得網頁目標網址?在Android中獲取目標網址

我解釋一下:我在我的網頁WebView;當我點擊網頁中的鏈接時,我想要鏈接的地址,這可能嗎?

非常感謝。

回答

0
webview.setWebViewClient(new WebViewClient() { 
     public boolean shouldOverrideUrlLoading(WebView view, String url) { 
      Log.i(TAG, "Processing webview url click..."); 
      view.loadUrl(url); 
      return true; 
     } 

     public void onPageFinished(WebView view, String url) { 
      Log.i(TAG, "Finished loading URL: " +url); 
      if (progressBar.isShowing()) { 
       progressBar.dismiss(); 
      } 
     } 

     public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { 
      Log.e(TAG, "Error: " + description); 
      Toast.makeText(activity, "Oh no! " + description, Toast.LENGTH_SHORT).show(); 
      alertDialog.setTitle("Error"); 
      alertDialog.setMessage(description); 
      alertDialog.setButton("OK", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int which) { 
        return; 
       } 
      }); 
      alertDialog.show(); 
     } 
    }); 
    webview.loadUrl("http://www.google.com"); 
+0

沒關係!非常感謝 –