Android, Codes and Tips

Just in

12/15/2019

How to add loading progressBar in Android Studio app

After working and searching for hours and you can't get the solution you are looking for. You are welcome to the home of Android Developer. If you have
being using Android Studio for writing Java apps, Java codes is everything sensitive raging from capital letters, punctuation errors, misspelled of words and plugin updates.

Android Studio comes up with new updates always which depreciated the older once. A code you write today, use it and develop an app may be outdated and depreciated tomorrow. If you copy somebody's code or forked a code from github, there are chances that the code which worked earlier won't work again unless you do serious editing.



In MainActivity Java Class add below codes

//Progress bar
        progressBar = findViewById(R.id.progressBar);
        progressBar.setMax(100);
    }


    private class WebViewClientDemo extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            progressBar.setVisibility(View.GONE);
            progressBar.setProgress(100);
            mySwipeRefreshLayout.setRefreshing(false);
        }
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            progressBar.setVisibility(View.VISIBLE);
            progressBar.setProgress(0);
        }

    }
    private class WebChromeClientDemo extends WebChromeClient {
        public void onProgressChanged(WebView view, int progress) {
            progressBar.setProgress(progress);
        }
    }

No comments:

Post a Comment