Simply explain how to use WebView to load Baidu's web acticity code
Public class mainactivity extends Activity { PrivateWebView WebView;@Override protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_main); WebView = (WebView) Findviewbyid (R.id.webview); Webview.getsettings (). setjavascriptenabled (true); Webview.setwebviewclient (NewWebviewclient () {@Override Public Boolean shouldoverrideurlloading(WebView view, String URL) {view.loadurl (URL);return true; } }); Webview.loadurl ("Http://www.baidu.com"); }
Layout code
<LinearLayout 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" Android:paddingleft="@dimen/activity_horizontal_margin" Android:paddingright="@dimen/activity_horizontal_margin" Android:paddingtop="@dimen/activity_vertical_margin" Android:paddingbottom="@dimen/activity_vertical_margin" Tools:context=". Mainactivity " android:orientation="Vertical"> <WebViewandroid:layout_width="Match_parent"android:layout_height= "Match_parent" android:id="@+id/webview" > </WebView></linearlayout>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Android Home Browser Webview-android Learning Tour (64)