9
如何打開網頁中的鏈接到新的活動(什麼包含WebView)?如何打開WebView鏈接到新的活動?
我有網頁在哪裏是列表,每個列表項都包含不同的鏈接。所以我希望當用戶按下第一個項目時,它會打開第二個活動並將該鏈接加載到第二個活動的WebView。希望你明白我想問什麼:)
這可能嗎?
如何打開網頁中的鏈接到新的活動(什麼包含WebView)?如何打開WebView鏈接到新的活動?
我有網頁在哪裏是列表,每個列表項都包含不同的鏈接。所以我希望當用戶按下第一個項目時,它會打開第二個活動並將該鏈接加載到第二個活動的WebView。希望你明白我想問什麼:)
這可能嗎?
可以重寫URL鏈接的點擊次數和每次點擊打開活動:
webView = new WebView(this);
webView.setWebViewClient(new WebViewClient()
{
// Override URL
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
Intent intent = new Intent(...);
startActivity(intent);
return true;
}
});
一些參數值得加入
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setBuiltInZoomControls(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
WebView.setWebContentsDebuggingEnabled(true);
}
mWebView.addJavascriptInterface(
new WebAppInterface(mParentActivity.getApplicationContext()),
"Android");
mWebView.setWebViewClient(new CustomWebViewClient()
);
如何獲取該鏈接並將其傳遞給webView.loadUrl(url); (在第二項活動中)? – Eljas 2012-02-22 02:15:34
您可以將URL作爲您的意圖額外傳遞。然後在第二個活動中,您可以提取額外的(URL)並創建另一個Web視圖並加載該URL。在這裏看到更多關於意圖和額外的信息:http://stackoverflow.com/questions/4233873/how-to-get-extra-data-from-intent-in-android – triad 2012-02-22 17:43:56
@triad:我已經通過網址,並得到在第二個活動,但webview.loadUrl(newurl),newurl不顯示... – Ponmalar 2012-05-11 06:57:41