layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/wvWeb" />
</LinearLayout>
In your Activity
VARIABLES GLOBALES
ProgressDialog dialog = null;
public static WebView wvFacebook;
final String url="https://www.facebook.com/";
DENTRO DE TU ACTIVITY
dialog = ProgressDialog.show(getActivity(), "",
"Cargando...", true);
if (checkConnectivity()) {
wvFacebook = (WebView)findViewById(R.id.wvWeb);
WebSettings webSettings = wvFacebook.getSettings();
wvFacebook.getSettings().setJavaScriptEnabled(true);
wvFacebook.setWebViewClient(new MyWebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
dialog.dismiss();
}
});
wvFacebook.loadUrl(url);
} else {
new Handler().postDelayed(new Runnable() {
public void run() {
dialog.dismiss();
Toast.makeText(getActivity(), "Sin conexión a Internet...", Toast.LENGTH_SHORT).show();
}
;
}, 8000);
}
CHECAR INTERNET
private boolean checkConnectivity() {
boolean enabled = true;
ConnectivityManager connectivityManager = (ConnectivityManager) .getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = connectivityManager.getActiveNetworkInfo();
if ((info == null || !info.isConnected() || !info.isAvailable())) {
Toast.makeText(getActivity(), "Problemas con su conexión a Internet...", Toast.LENGTH_SHORT).show();
enabled = false;
}
return enabled;
}
//ESTA ES IMPORTANTE PARA LA NAVEGACION
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return true;
}
}
//Si quiere controlar la navegación hacia atrás, es decir, cuando navegas dentro de tu Webview, y quieres dar back sin salirte del Web usa esto:
@Override
public void onBackPressed() {
if (wvFacebook.canGoBack()) {
wvFacebook.goBack();
}