based on a certain understanding and understanding of the WebView control, we can continue to study this control, this article mainly describes how to make WebView and progressdialog combination.
The WebView component supports loading Web pages directly and can be viewed as a browser, with the following steps:
1. Create a new XML layout file as follows:
<span style= "FONT-SIZE:18PX;" ><relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools " 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"/></relativelayout></span>
2. Initialize the control and set the corresponding parameters in the main activity
<span style= "FONT-SIZE:18PX;" >package Com.happy.wbpd;import Android.app.activity;import Android.app.alertdialog;import Android.app.progressdialog;import Android.content.dialoginterface;import Android.os.bundle;import Android.view.keyevent;import Android.webkit.webview;import Android.webkit.webviewclient;import Android.widget.progressbar;import Android.widget.toast;public class Mainactivity extends Activity {private WebView Webview;private alertdialog alertdialog;private progressdialog progressBar; @Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); InitWebView ();} /** * Initialize WebView */private void Initwebview () {WebView = (WebView) This.findviewbyid (r.id.webview);p Rogressbar = Progress Dialog.show (mainactivity.this, NULL, "Entering webpage, please later ..."); Webview.getsettings (). Setjavascriptenabled (True); Webview.loadurl ("http://www.baidu.com/"); alertdialog = new Alertdialog.builder (mainactivity.this). Create (); Webview.setwEbviewclient (New Webviewclient () {@Overridepublic void onpagefinished (WebView view, String URL) {if ( Progressbar.isshowing ()) {Progressbar.dismiss ();}} @Overridepublic void Onreceivederror (WebView view, int errorcode,string description, String failingurl) {Toast.maketext (Mainactivity.this, "page loading error! ", Toast.length_long); Alertdialog.settitle (" ERROR "); Alertdialog.setmessage (description); Alertdialog.setbutton (" Ok ", new Dialoginterface.onclicklistener () {@Overridepublic void OnClick (Dialoginterface dialog,int which) {}}); Alertdialog.show ();} @Overridepublic Boolean shouldoverrideurlloading (WebView view, String URL) {view.loadurl (URL); return true;});} @Overridepublic boolean onKeyDown (int keycode, keyevent event) {if (keycode = = Keyevent.keycode_back && webview.c Angoback ()) {webview.goback (); return true;} Return Super.onkeydown (KeyCode, event);}} </span>
3. If you need to add access to the Internet in Androidmanifest.xml, you cannot display:
<uses-permission android:name= "Android.permission.INTERNET"/>
The logic is relatively simple, plus today is more busy, so the general introduction, the next article will say WebView and JavaScript call each other and the ListView join WebView to implement the drop-down refresh.
(iii) Android Webview in Depth (medium)