要在WebView中处理链接,可以使用WebViewClient类的shouldOverrideUrlLoading方法.考虑以下示例;
WebView webView = (WebView) findViewById(R.id.infoView);
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// Assuming you are giving link to some PDF file.
if (url.contains(".pdf")) {
// Now do what you want to with the url here
}
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
这样,您可以拦截在WebView中点击的任何链接,然后执行您想要的任何操作.
| 归档时间: |
|
| 查看次数: |
1789 次 |
| 最近记录: |