1. Layout file fragment: Res-layout
<android:id= "@+id/toweb" android:layout_width= "Fill_parent " android:layout_height=" fill_parent "/>
2.Java Fragment: src
@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); //WebViewWebView browser=(WebView) Findviewbyid (R.id.toweb); Browser.loadurl ("Http://www.baidu.com"); //set to freely scale Web pagesBrowser.getsettings (). Setsupportzoom (true); Browser.getsettings (). Setbuiltinzoomcontrols (true); //If the page is linked, if you want to click on the link to continue responding in the current browser,//instead of the newly opened Android system browser should be linked, must overwrite WebView webviewclient objectBrowser.setwebviewclient (Newwebviewclient () { Public Booleanshouldoverrideurlloading (WebView view, String URL) {//Override this method to indicate that clicking on a link in the Web page or jumping in the current webview does not jump to the browser .view.loadurl (URL); return true; } }); } //Go back@Override Public BooleanOnKeyDown (intKeyCode, KeyEvent event) {WebView Browser=(WebView) Findviewbyid (R.id.toweb); //Check If the key event is the back button and if there's history if((keycode = = Keyevent.keycode_back) &&Browser.cangoback ()) {Browser.goback (); return true; } //return true; //If It wasn ' t the back key or there's no Web page history, bubble up to the default//system behavior (probably exit the activity) return Super. OnKeyDown (KeyCode, event); }
3. Androidmanifest.xml set permissions, otherwise cannot access
<!-- Add this permission, WebView can access the Web page - < android:name= "Android.permission.INTERNET"></ Uses-permission>
Andriod using WebView controls to embed pages in the app