This is how I did in my Application
public class PayYouMoneyFragment extends Fragment {
/** The Constant PAYU_MONEY_URL. */
private static final String PAYU_MONEY_URL = "https://www.payumoney.com/paybypayumoney/#/BCDCEAE6A98116CB48BDE55C440BC69D";
/**
* Instantiates a new pay you money fragment.
*/
public PayYouMoneyFragment() {
// Empty constructor required for fragment subclasses
}
/**
* The Class MyWebViewClient.
*/
private class MyWebViewClient extends WebViewClient {
/** The web view previous state. */
private int webViewPreviousState;
/** The page started. */
private final int PAGE_STARTED = 0x1;
/** The page redirected. */
private final int PAGE_REDIRECTED = 0x2;
/** The dialog. */
Dialog dialog = new Dialog(getActivity());
/* (non-Javadoc)
* @see android.webkit.WebViewClient#shouldOverrideUrlLoading(android.webkit.WebView, java.lang.String)
*/
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
/* (non-Javadoc)
* @see android.webkit.WebViewClient#onPageStarted(android.webkit.WebView, java.lang.String, android.graphics.Bitmap)
*/
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
webViewPreviousState = PAGE_STARTED;
if (dialog == null || !dialog.isShowing())
dialog = ProgressDialog.show(getActivity(), "",
"Loading Please Wait", true, true,
new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
// do something
}
});
}
/* (non-Javadoc)
* @see android.webkit.WebViewClient#onPageFinished(android.webkit.WebView, java.lang.String)
*/
@Override
public void onPageFinished(WebView view, String url) {
if (webViewPreviousState == PAGE_STARTED) {
dialog.dismiss();
dialog = null;
}
}
}
/** The btn back. */
Button btnBack;
/** The webview. */
WebView webview;
/* (non-Javadoc)
* @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.payumoney_fragment, container,
false);
webview = (WebView) rootView.findViewById(R.id.payu_webview);
webview.setWebViewClient(new MyWebViewClient());
webview.getSettings().setDomStorageEnabled(true);
webview.getSettings().setJavaScriptEnabled(true);
openURL();
return rootView;
}
/**
* Opens the URL in a browser.
*/
private void openURL() {
webview.loadUrl(PAYU_MONEY_URL);
webview.requestFocus();
}
public static Fragment newInstance() {
return new PayYouMoneyFragment();
}
}
and here is payumoney layout
I have also uploaded generalized version on Github :-
https://github.com/hiteshsahu/Android-Universal-Web-Content-Loader