- Request feature of Window.FEATURE_PROGRESS:
Add the code getWindow().requestFeature(Window.FEATURE_PROGRESS) before setContentView().
- Implement your custom WebChromeClient class with onProgressChanged() method overrided, to call setProgress() method.
- Updated onCreate() should like this:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main);
webView = (WebView)findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.setWebViewClient(new MyWebViewClient());
webView.loadUrl(DEFAULT_URL);
final Activity activity = this;
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
// Activities and WebViews measure progress with different scales.
// The progress meter will automatically disappear when we reach 100%
activity.setProgress(progress * 100);
}});
}
next:
- Handle the Back button in WebView, to back in history.
related:
- Create your own London 2012 App
No comments:
Post a Comment