Display Progress Bar on WebView when loading
Continuous work on last post Enable JavaScript and built-in zoom control of WebView; to display progress bar on WebView when loading:
- 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:
- 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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| 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 ); }}); }
akm www.cdacians.com |
No comments:
Post a Comment