How To Add Progress Bar On WebView

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);
}
});




Leave a Reply