Here I am writing code to load url on WebView.
We need to create WebView client where we get the event of page finished.
Then simply showing ProgressDialog and dismiss it on onPageFinished().
WebView myWebView ;
myWebView = (WebView)findViewbyId(R.id.my_web_view);
myWebView.setWebViewClient(new WebViewClient() {
ProgressDialog mProgressDialog;
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
//Show loader on url load
public void onLoadResource (WebView view, String url) {
if (mProgressDialog == null) {
mProgressDialog = new ProgressDialog(MyActivity.this);
mProgressDialog.setMessage("Loading...");
mProgressDialog.show();
}
}
public void onPageFinished(WebView view, String url) {
try{
if (mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
mProgressDialog = null;
}
}catch(Exception e){
e.printStackTrace();
}
}
});
// Javascript inabled on webview
webView.getSettings().setJavaScriptEnabled(true);
//Load url in webview
webView.loadUrl(url);
}
0 Comment(s)