先截上两张图:

image

 

image

需要注意的:

1.开启权限

<uses-permission android:name="android.permission.INTERNET" />

2.覆盖webview的WebViewClient对象

webView.setWebViewClient(new WebViewClient(){ 
            public boolean shouldOverrideUrlLoading(WebView view, String url) { 
                view.loadUrl(url); 
                return true; 
            } 
        });

 

3.需要在当前Activity中处理并消费掉该Back事件

public boolean onKeyDown(int keyCode, KeyEvent event) { 
            if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) { 
                mWebView.goBack(); 
                return true; 
            } 
            return super.onKeyDown(keyCode, event); 
        } 

4.主要的代码:

 

this.webView= (WebView)findViewById(R.id.webview);
    this.webView.getSettings().setSupportZoom(false);
    this.webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
   
    webView.setWebViewClient(new WebViewClient(){ 
        public boolean shouldOverrideUrlLoading(WebView view, String url) { 
            view.loadUrl(url); 
            return true; 
        } 
    });

    this.webView.loadUrl("http://m.foreverlove.us/");
}
    public boolean onKeyDown(int keyCode, KeyEvent event) { 
        if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) { 
            webView.goBack(); 
            return true; 
        } 
        return super.onKeyDown(keyCode, event); 
    } 

参考网站: http://www.congci.com/item/android-webview