参考《Android Developers》,感谢

  1. You now have a simplest web page viewer. It’s not quite a browser yet because as soon as you click a link, the default Android Browser handles the Intent to view a web page, because this Activity isn’t technically enabled to do so. Instead of adding an intent filter to view web pages, you can override the WebViewClient class and enable thisActivity to handle its own URL requests.

  2. In the HelloAndroid Activity, add this nested class:
    private class HelloWebViewClient extends WebViewClient {
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
    return true;
  3. Then towards the end of the onCreate(Bundle) method, set an instance of the HelloWebViewClient as the WebViewClient:
    mWebView.setWebViewClient(new HelloWebViewClient());


public boolean shouldOverrideUrlLoading (WebView view, String url)

Since: API Level 1

Give the host application a chance to take over the control when a new url is about to be loaded in the current WebView. If WebViewClient is not provided, by default WebView will ask Activity Manager to choose the proper handler for the url. If WebViewClient is provided, return true means the host application handles the url, while return false means the current WebView handles the url.

view The WebView that is initiating the callback.
url The url to be loaded.
  • True if the host application wants to leave the current WebView and handle the url itself, otherwise return false.



邮箱地址不会被公开。 必填项已用*标注