2011-12-19 70 views
0

我用webview加载了一个网页。有没有一种方法来监听点击操作,以了解什么超链接点击webview?例如,如果点击超级链接1,然后切换到本地代码页1,如果点击超级链接2,然后跳转到本地代码页2 ....可以在Android的Webview上监听点击内容

回答

5

看一看这样的:

http://developer.android.com/guide/webapps/webview.html

您可能会发现这个有用:

@Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 
     if (Uri.parse(url).getHost().equals("www.example.com")) { 
      // This is my web site, so do not override; let my WebView load the page 
      return false; 
     } 
     // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs 
     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
     startActivity(intent); 
     return true; 
    }