My app has two files:
- MainActivity.java - extends SherlockFragmentActivity
- MyWebviewFragment.java - extends SherlockFragment
The app consists of 7 tabs, all fragments (MyWebviewFragment) that implement a single WebView object. Each tab/fragment adds a single action icon (Refresh) to the actionbar when it's active. I want to show a ProgressBar while the WebView is loading and I want to use the ActionBar as the progress indicator. I don't want to use a ProgressDialog or ProgressDialogFragment because the app is implemented as a ViewPager. ViewPager apps not only load the fragment you are on, but the adjacent fragments. If I show any kind of ProgressDialog, I get not only the ProgressDialog for the current fragment/WebView, but also for the adjacent fragments. In other words, I get 2 dialogs.
I can avoid this by using a ProgressBar instead of a ProgressDialog. I've been able to create a ProgressBar and hide it using the layout but I'd prefer to do it this way:
- Change the actionbar title to "Loading ..."
- Use the actionbar as the ProgressBar
If I wanted to do this with a non-fragment implementation, I'd do something like this:
// Adds Progrss bar Support
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main );
// Makes Progress bar Visible
getWindow().setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
...
mWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
//Make the bar disappear after URL is loaded, and changes string to Loading...
MyActivity.setTitle("Loading...");
MyActivity.setProgress(progress * 100); //Make the bar disappear after URL is loaded
// Return the app name after finish loading
if(progress == 100)
MyActivity.setTitle(R.string.app_name);
}
});
But... as I mentioned, I'm using an ActionBarSherlock and not a simple title bar. I'm also using fragments that implement WebViews. The above code won't work for a class derived from SherlockFragment. I'm sure this can be done by adding code to the onCreateView method within the fragment but I'm not sure how to do it.
Is this type of functionality even supported? If so, how would I do it?
Thanks in advance to anyone that can help. I really appreciate it.