Welcome to Tech Pro Advice. We post about technology, including tech reviews, how to Fix Windows PC errors, Microsoft Word Tips, Excel tips, Facebook tips, Youtube tips & Updates. And other content like a how-to, science, digital culture, innovation, or just awesome stuff to watch from Tech Pro Advice. Subscribe to This Channel For apps, Software, Gadgets Review, Unboxing, Tips, And Tricks.

Subscribe Us

Monday, February 15, 2021

How To Add Progress Bar On WebView

 

Add this code in  activity_main.xml(Copy and Paste)


SAB SE PAHLE LAYOUT CHAGE KARO

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

<ProgressBar

    android:layout_width="match_parent"
android:layout_height="8dp"
android:id="@+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_marginTop="-3dp"
android:progress="20"
android:visibility="gone"/>

Add this code in  main.Activity.java(Copy and Paste)


( AFTER private WebView mywebView; )

ProgressBar progressBar;
ProgressDialog progressDialog;


 AFTER    setContentView(R.layout.activity_main);

progressBar=(ProgressBar) findViewById(R.id.progress);
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Loading wait...");


URL KE BAD

mywebView.setWebChromeClient(new WebChromeClient(){
@Override
public void onProgressChanged(WebView view, int newProgress) {
progressBar.setVisibility(View.VISIBLE);
progressBar.setProgress(newProgress);
setTitle("Loading...");
progressDialog.show();
if (newProgress == 100){
progressBar.setVisibility(View.GONE);
setTitle(view.getTitle());
progressDialog.dismiss();
}

super.onProgressChanged(view, newProgress);
}
});


No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages

SoraTemplates

Best Free and Premium Blogger Templates Provider.

Buy This Template