0
我能夠成功地在webview中加載html頁面。我也可以通過設置webviewclient來獲取在webview上點擊的url。但我想要的是不同的東西,我有一個web視圖加載一個網頁,並點擊一個按鈕,我希望所有的網址出現在該網頁。我該怎麼做呢?在頁面加載時獲取webview中的所有url
到目前爲止,我已經嘗試過的代碼是
dialog = ProgressDialog.show(Activity.this, null, null);
dialog.setContentView(R.layout.loader);
w.setWebViewClient(new MyWebViewClient());
w.loadDataWithBaseURL("same://ur/l/tat/does/not/work", string_html,
"text/html", "utf-8", null);
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
if (url.startsWith("http://")) {
System.out.println("INSIDE IF"); // NON-NLS
view.stopLoading();
urlToSend = url;
System.out.println("in " + urlToSend);
Intent intent = new Intent(DetailNews.this, Web.class);
intent.putExtra("Web", url);
startActivity(intent);
}
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
dialog.dismiss();
}
}