Android Development _ About WebView loading page blank question

Source: Internet
Author: User

According to my own tests, I found that sometimes when you open a Web page with an app, some pages take a long time before they load, and some of them come out (like Baidu).

When the load time is too long, the display is a blank interface, in fact, is not a code problem, but to open the page is too large.

So in order to improve the user experience, we have to find a way to add something in the case of waiting on this blank interface.

The first thing that comes to mind is the cue box

Specific operation

Package Com.example.qunxiong;import;import;import;import Android.content.dialoginterface;import Android.os.bundle;import Android.util.log;import Android.view.keyevent;import Android.view.window;import Android.webkit.WebSettings;import Android.webkit.webview;import Android.webkit.webviewclient;import android.widget.Toast; Public classWeb_shijianjinbi extends Activity {PrivateWebView WebView; Private StaticFinal String TAG ="Web_shijianjinbi";//class name    PrivateProgressDialog ProgressBar; /** Called when the activity is first created.*/@Override Public voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);         Requestwindowfeature (Window.feature_no_title);  Setcontentview (r.layout.web_show); The corresponding layout This. WebView =(WebView) Findviewbyid (;//This is the ID of the WebView control in Layout websettings settings=webview.getsettings (); Settings.setjavascriptenabled (true);         Webview.setscrollbarstyle (Webview.scrollbars_outside_overlay); Final Alertdialog Alertdialog=NewAlertdialog.builder ( This). Create (); ProgressBar= (Web_shijianjinbi. This,"here is the title of the Cue box","here is the content of the cue box"); Webview.setwebviewclient (Newwebviewclient () { PublicBoolean shouldoverrideurlloading (WebView view, String URL) {log.i (TAG,"processing webview URL click ...");                View.loadurl (URL); return true; }              Public voidonpagefinished (WebView view, String URL) {log.i (TAG,"finished loading URL:"+URL); if(Progressbar.isshowing ()) {Progressbar.dismiss (); }            }              Public voidOnreceivederror (WebView view,intErrorCode, string description, String failingurl) {LOG.E (TAG,"Error:"+description); Toast.maketext (Web_shijianjinbi. This,"Oh no!"+description, Toast.length_short). Show (); Alertdialog.settitle ("Error");                Alertdialog.setmessage (description); Alertdialog.setbutton ("OK",NewDialoginterface.onclicklistener () { Public voidOnClick (Dialoginterface Dialog,intwhich) {                        return;                }                });   ();        }        }); //here is the page to open
Webview.loadurl (""); }}

The following is a simple layout file

1<?xml version="1.0"encoding="Utf-8"?>2<linearlayout xmlns:android="" 3android:orientation="Vertical" 4Android:layout_width="fill_parent" 5android:layout_height="fill_parent" 6>7<WebView8Android:id="@+id/webview" 9Android:layout_width="fill_parent" Tenandroid:layout_height="fill_parent"  One/> A</LinearLayout>

Android Development _ About WebView loading page blank question

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.