我使用webview来加载网页.有没有办法听点击动作,知道什么超链接点击webview?例如,如果单击超链接1然后切换到本机代码页1,如果单击超链接2然后跳转到本机代码页2 ....
在WebView中使用JavaScript可以做到这一点.请参考下面的链接.
Android WebView WebChromeClient示例教程
http://developer.android.com/guide/webapps/webview.html
看看这个:
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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1618 次 |
| 最近记录: |