+ // Save the URL to formattedUrlString and update urlTextBox before loading mainWebView.
+ mainWebView.setWebViewClient(new WebViewClient() {
+ public boolean shouldOverrideUrlLoading(WebView view, String url) {
+ formattedUrlString = url;
+ urlTextBox.setText(formattedUrlString);
+ mainWebView.loadUrl(formattedUrlString);
+ return true;
+ }
+ });
+
+ // Update the progress bar when a page is loading.
+ mainWebView.setWebChromeClient(new WebChromeClient() {
+ public void onProgressChanged(WebView view, int progress) {
+ progressBar.setProgress(progress);
+ if (progress < 100) {
+ progressBar.setVisibility(View.VISIBLE);
+ } else {
+ progressBar.setVisibility(View.GONE);
+
+ // Stop the refreshing indicator if it is running.
+ swipeToRefresh.setRefreshing(false);
+
+ // Update the URL in urlTextBox. It is necessary to do this after the page finishes loading to get the final URL, which can change during load.
+ formattedUrlString = mainWebView.getUrl();
+ urlTextBox.setText(formattedUrlString);
+ }
+ }
+ });