Progress Bar For webview App on url Loading

XML File Code For Progress bar

<WebView
android:id="@+id/wv"
android:layout_width="match_parent"
android:layout_height="match_parent"></WebView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Loading..."
android:background="#00000000"

android:textColor="#2203ba"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_below="@+id/progressBar2"
android:id="@+id/textView"
/>-->

<ProgressBar
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"

android:layout_centerHorizontal="true"
android:background="#00000000"
android:layout_centerVertical="true"
android:id="@+id/progressBar2"
/>

Define id In the Java Class

bar = (ProgressBar) findViewById(R.id.progressBar2);
text1 = (TextView) findViewById(R.id.textView);
wv = (WebView) findViewById(R.id.wv);
// wv.getSettings().setPluginState(true);
wv.getSettings().setBuiltInZoomControls(false);
wv.getSettings().setSupportZoom(false);
wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
wv.getSettings().setAllowFileAccess(true);
wv.getSettings().setJavaScriptEnabled(true);
WebSettings webSettings = wv.getSettings();
wv.loadUrl("http://www.***.com/");
wv.setWebViewClient(new WebViewClient());
wv.setWebViewClient(new myWebclientt());

Now in the Last Define the Visiblity of progress bar on loading time and after loading finish

public class myWebclientt extends WebViewClient {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
bar.setVisibility(View.GONE);
text1.setVisibility(View.GONE);
}

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
bar.setVisibility(View.VISIBLE);
text1.setVisibility(View.VISIBLE);


}

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {



return super.shouldOverrideUrlLoading(view, url);



}
}

Here you Done it 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *