WebView is a common component, especially if the current H5 is so popular, this article describes the general usage of WebView in the project. Generally webview loading process before the current network to make a judgment, without the case of the network to give a hint. There is a network case with a ProgressBar showing the current progress, OK, on the code.
First step: Design the page
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" match_parent " android:layout_height=" match_parent " android:o rientation= "vertical" > <include layout= "@layout/layout_head"/> <progressbar android:id= "@+id/pb" style= "android:attr/progressbarstylehorizontal" android:layout_width= "Fill_parent " android:layout_height= "2dip" android:indeterminateonly= "false" android:max= " android: progressdrawable= "@drawable/progress_bar_states_new" > </ProgressBar> <webview Android:id= "@+id/webview" android:layout_width= "match_parent" android:layout_height= "match_parent"/ ></LinearLayout>
Step Two: Write activity
/** * */package com.android.inputmethod.latin.activity;import android.app.activity;import Android.os.Bundle;import Android.view.view;import Android.view.view.onclicklistener;import Android.webkit.webchromeclient;import Android.webkit.webview;import Android.widget.linearlayout;import Android.widget.progressbar;import Android.widget.textview;import com.android.inputmethod.latin.r;import com.dotc.util.networkutil;/** * @author Figo * */public class Commonproblemactivity extends Activity {private WebView wb; ProgressBar PB; Private LinearLayout Mlayoutback; Private TextView Mtvtitle; @Override protected void OnCreate (Bundle savedinstancestate) {//TODO auto-generated method stub super.o Ncreate (savedinstancestate); Setcontentview (R.layout.activity_common_problem); } @Override protected void Onresume () {//TODO auto-generated Method Stub super.onresume (); Initview (); } private void Initview () {try { PB = (ProgressBar) Findviewbyid (R.ID.PB); Pb.setmax (100); Mlayoutback = (linearlayout) Findviewbyid (r.id.layout_back); Mlayoutback.setonclicklistener (New Onclicklistener () {@Override public void OnClick (View ar G0) {finish (); } }); Mtvtitle = (TextView) Findviewbyid (r.id.txt_title); Mtvtitle.settext (getString (R.string.lbl_common_problem)); This write will jump directly to the browser//Wb.loadurl ("http://www.baidu.com"); Use the Webviewclient Web page to display WB = (WebView) Findviewbyid (R.id.webview) in the current activity; Wb.getsettings (). Setjavascriptenabled (True); Wb.getsettings (). Setsupportzoom (True); Wb.getsettings (). Setbuiltinzoomcontrols (True); Wb.setwebchromeclient (New Webviewclient ()); if (! Networkutil.isnetworkuseful (Commonproblemactivity.this)) {String customhtml = "
63:webview common usage of Android development step by step