I have looked at a question similar to this here but as I am a newbie could someone explain how to get this to work in a WebView or at least how to set a 10 second time delay so people know that it's loading?
Android ProgressBar is a graphical view indicator that shows some progress. Android progress bar displays a bar representing the completing of the task. Progress bar in android is useful since it gives the user an idea of time to finish its task.
Android ProgressDialog is a dialog box/dialog window which shows the progress of a task. Android Progress Dialog is almost same as ProgressBar with the exception that this is displayed as a dialog box. In order to create a ProgressDialog to display a ProgressBar we need to instantiate it like this.
For a horizontal progress bar, you first need to define your progress bar and link it with your XML file like this, in the onCreate
:
final TextView txtview = (TextView)findViewById(R.id.tV1); final ProgressBar pbar = (ProgressBar) findViewById(R.id.pB1);
Then, you may use onProgressChanged Method in your WebChromeClient:
MyView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { if(progress < 100 && pbar.getVisibility() == ProgressBar.GONE){ pbar.setVisibility(ProgressBar.VISIBLE); txtview.setVisibility(View.VISIBLE); } pbar.setProgress(progress); if(progress == 100) { pbar.setVisibility(ProgressBar.GONE); txtview.setVisibility(View.GONE); } } });
After that, in your layout you have something like this
<TextView android:text="Loading, . . ." android:textAppearance="?android:attr/textAppearanceSmall" android:id="@+id/tV1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textColor="#000000"></TextView> <ProgressBar android:id="@+id/pB1" style="?android:attr/progressBarStyleHorizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:padding="2dip"> </ProgressBar>
This is how I did it in my app.
I have just found a really good example of how to do this here: http://developer.android.com/reference/android/webkit/WebView.html . You just need to change the setprogress from:
activity.setProgress(progress * 1000);
to
activity.setProgress(progress * 100);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With