i created a webview inside my Android app with the following acitivity:
public class WebPageOpener extends Activity {
private WebView webView;
@SuppressLint({ "SetJavaScriptEnabled", "DefaultLocale" })
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
Bundle extras = getIntent().getExtras();
String url = extras.getString("url");
webView = (WebView) findViewById(R.id.webView);
webView.setWebViewClient(new MyBrowser());
// settings
WebSettings webSettings = webView.getSettings();
webSettings.setSaveFormData(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setSupportZoom(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setLoadsImagesAutomatically(true);
webSettings.setJavaScriptEnabled(true);
webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
webView.loadUrl(url);
}
private class MyBrowser extends WebViewClient {
final ProgressBar progressBar = (ProgressBar) findViewById(R.id.ProgressBar);
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
Log.d("TAG", url);
progressBar.setVisibility(View.VISIBLE);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Log.d("TAG", "failed: " + failingUrl + ", error code: " + errorCode + " [" + description + "]");
}
public void onPageFinished(WebView view, String url) {
progressBar.setVisibility(View.GONE);
}
}
}
Here is the related XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ProgressBar
android:id="@+id/ProgressBar"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleLarge"
android:visibility="gone"/>
</RelativeLayout>
I would avoid that users can tap on any buttons or image inside the webpage untill the webpage finish to load. In other words users can interact with webpage only when progress bar disappears. Any way?