2013-03-18 15 views

回答

2

您只需要设置一个WebViewClient为您WebView,然后所有链接将会打开它同样WebView

WebView.setWebViewClient(new WebViewClient()); 
1
private class myCustomWebViewClient extends WebViewClient { 
    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 
    //here load the url in your webview 
    webview.loadUrl(url); 

    return true; 
    } 

这为集的网页视图

webView.setWebViewClient(new myCustomWebViewClient()); 
0

你应该添加你自己的webViewClient。

WebView myWebView = (WebView) findViewById(R.id.webview); 
myWebView.setWebViewClient(new MyWebViewClient()); 
在webViewClient可以覆盖shouldOverrideUrlLoading()方法是像

@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; 
    } 

我希望你觉得它有用。

相关问题