The same question has been answered multiple times. And all the answers refer to the this post. Though this post has warnings in the end, I could not find any other eaiser way to achive what tou are looking for.
Below is the copy-paste of the code from this post.
final Context myApp = this;
/* An instance of this class will be registered as a JavaScript interface */
class MyJavaScriptInterface
{
@JavascriptInterface
@SuppressWarnings("unused")
public void processHTML(String html)
{
// process the html as needed by the app
}
}
//Edit 1 start
final ProgressDialog pd = ProgressDialog.show(OnlinePaymentActivity.this, "", "Please wait, your transaction is being processed...", true);
//Edit 1 end
final WebView browser = (WebView)findViewById(R.id.browser);
/* JavaScript must be enabled if you want it to work, obviously */
browser.getSettings().setJavaScriptEnabled(true);
/* Register a new JavaScript interface called HTMLOUT */
browser.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT");
/* WebViewClient must be set BEFORE calling loadUrl! */
browser.setWebViewClient(new WebViewClient() {
/////Edit 2 start
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon)
{
If(browser.getVisibility() == View.VISIBLE)
{
browser.setVisibility(View.GONE);
}
pd.show();
}
///// Edit 2 end
@Override
public void onPageFinished(WebView view, String url)
{
//Edit 3 start
If(browser.getVisibility() == View.GONE)
{
browser.setVisibility(View.VISIBLE);
}
pd.dismiss();
// Edit 3 end
/* This call inject JavaScript into the page which just finished loading. */
browser.loadUrl("javascript:window.HTMLOUT.processHTML('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
}
});
/* load a web page */
browser.loadUrl("http://lexandera.com/files/jsexamples/gethtml.html");