您只需要實施shouldOverrideUrlLoading()
。從我最近的一個項目一個片段:
public class WebViewCustom extends Activity {
WebView mWebView;
String mUrl;
String urlHistory;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lessons_page);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.setWebViewClient(new WebViewOverrideUrl());
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.loadUrl("YOUR-URL-HERE");
}
private class WebViewOverrideUrl extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
編碼愉快!
輝煌的作品魅力謝謝! –