
In this article, we will show you Android WebView ProgessBar while loading . This article will give you simple example of Android WebView ProgessBar while loading . you will learn Android WebView ProgessBar while loading.
code copy and past main.java file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | final ProgressDialog progressBar = new ProgressDialog(MainActivity. this ); progressBar.setMessage( "Please wait..." ); webView.setWebViewClient( new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true ; } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super .onPageStarted(view, url, favicon); if (!progressBar.isShowing()) { progressBar.show(); } } public void onPageFinished(WebView view, String url) { if (progressBar.isShowing()) { progressBar.dismiss(); } } public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { if (progressBar.isShowing()) { progressBar.dismiss(); } } }); |
This is how to insert, MainActivity.java file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | public class MainActivity extends Activity { private WebView webView; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_main); webView = (WebView) findViewById(R.id.webView); final ProgressDialog progressBar = new ProgressDialog(MainActivity. this ); progressBar.setMessage( "Please wait..." ); webView.setWebViewClient( new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true ; } @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super .onPageStarted(view, url, favicon); if (!progressBar.isShowing()) { progressBar.show(); } } public void onPageFinished(WebView view, String url) { if (progressBar.isShowing()) { progressBar.dismiss(); } } public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { if (progressBar.isShowing()) { progressBar.dismiss(); } } }); } } |