Here's how I'm doing it.
In my main layout I have spots for the WebView and an ImageView. The WebView starts off 'gone' and the loadingimage is 'visible'.
<LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <ImageView android:id="@+id/imageLoading1" android:layout_height="wrap_content" android:layout_width="match_parent" android:visibility="visible" android:src="@drawable/loadingimage" /> <WebView android:id="@+id/webView1" android:layout_height="wrap_content" android:layout_width="match_parent" android:visibility="gone" /> </LinearLayout>
Then in the java I load the URL. Once the URL is done loading, I swap out the loading image for the WebView.
WebView wv; wv = (WebView) findViewById(R.id.webView1); wv.setWebViewClient(new WebViewClient() { //this is to catch link clicks on your page, to prevent opening a new browser @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } @Override public void onPageFinished(WebView view, String url) { //hide loading image findViewById(R.id.imageLoading1).setVisibility(View.GONE); //show webview findViewById(R.id.webView1).setVisibility(View.VISIBLE); } }); wv.loadUrl("http://www.yourdomain.com/blahblahblah.htm");
Please note: the onPageFinished method I use here works fine for my simple application, however, it might not work for your case. For deets about how to fully listen for a page to finish loading, see this thread --> How to listen for a WebView finishing loading a URL?