public class Webviewtest extends Activity {private WebView wv;private EditText et; @Overrideprotected void OnCreate (Bundle Savedinstancestate) {//TODO auto-generated method Stubsuper.oncreate (savedinstancestate); Setcontentview ( R.layout.webview); WV = (WebView) Findviewbyid (R.ID.WEBVIEW_WV); Wv.loadurl ("http://www.baidu.com"); Initwv (); et = ( EditText) Findviewbyid (R.id.webview_et); Et.setselection (Et.gettext (). Length ());} private void Initwv () {//TODO auto-generated method stub//set kernel, support Ajaxwv.setwebchromeclient (new Webchromeclient ());// New Webviewclient () default is based on WebKit kernel wv.setwebviewclient (new webviewclient () {//Jump from one page to another page, return True if the target page is open in the current WebView, the system default browser @overridepublic Boolean shouldoverrideurlloading (WebView view, String URL) will not be called {//TODO Auto-generated method Stubreturn true;} Called Method @overridepublic void onpagefinished (WebView view, String URL) when page load is complete {//TODO auto-generated method Stubtoast.maketext (Webviewtest.this, "finished loading! ", 0). Show (); super.onpagefinished (view, URL);} Method called when the page starts loading@Overridepublic void onpagestarted (WebView view, String URL, Bitmap favicon) {//TODO auto-generated method Stubet.settext (URL); super.onpagestarted (view, URL, favicon);}); /Set Support JS script wv.getsettings (). Setjavascriptenabled (true);//settings support finger magnification wv.getsettings (). Setsupportzoom (True); Wv.getsettings (). Setbuiltinzoomcontrols (True); public void load (view view) {//Load Urlwv.loadurl (Et.gettext (). toString (). Trim ());} public void reload (view view) {//Reload, Refresh page wv.reload ();} public void back (view view) {//Rewind wv.goback ();} Set (intercept) key touch time on Phone @overridepublic boolean onKeyDown (int keycode, keyevent event) {//TODO auto-generated method Stubswitch (keycode) {case KeyEvent.KEYCODE_BACK:wv.goBack (); break;default:break;} Return Super.onkeydown (KeyCode, event);}}
XML code:
<?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:orientation=" vertical " > <linearlayout android:layout_width= "match_parent" android:layout_height= "Wrap_content" and roid:orientation= "Horizontal" > <button android:layout_width= "wrap_content" Android:lay out_height= "Wrap_content" android:text= "Rewind" android:onclick= "Back"/> <edittext Android:id= "@+id/webview_et" android:layout_width= "match_parent" android:layout_height= "Wrap_con Tent "android:layout_weight=" 1 "android:text=" http://www. " Android:singleline= "true"/> <button android:layout_width= "Wrap_content" and roid:layout_height= "Wrap_content" android:text= "enter" android:onclick= "Load"/> <button android:layout_width= "Wrap_content" Android : layout_height= "wrap_content" android:text= "Refresh" android:onclick= "Reload"/> </li nearlayout> <webview android:id= "@+id/webview_wv" android:layout_width= "Match_parent" Andro id:layout_height= "Match_parent"/></linearlayout>
WebView Common methods of Android network technology