WebView basis of usage

WebView a new item, then modify the code activity_main.xml layout file, as follows:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.haobi.webviewdemo.MainActivity">

<WebView
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</ The LinearLayout>
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
10
. 11
12 is
13 is
then, in MainActivity modify the code as follows:

public class MainActivity extends AppCompatActivity {

@Override
protected void the onCreate (the Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
the setContentView (R.layout.activity_main);
//. 1, using the findViewById () method to obtain an instance of the WebView
WebView webView = (WebView) findViewById ( R. id.web_view);
// 2, call the WebView getSettings () method to set some browsers properties
// setJavaScriptEnabled () method is used to set whether to perform the method js page
webView.getSettings () setJavaScriptEnabled (to true);.
/ / 3, call WenView of setWebViewClient () method and pass an instance of WebViewClient
// role is the page jump when the goal is still the currently displayed page WebView, rather than open system browser
webView.setWebViewClient (new WebViewClient () );
// 4 () method and calls the URL into the WebView loadUrl
webView.loadUrl ( "http://www.baidu.com");
}
}
. 1
2
. 3
4
. 5
. 6
. 7
. 8
. 9
10
. 11
12 is
13 is
14
15
16
. 17
18 is
the last, requesting permission to join the network AndroidManifest.xml file.

<uses-permission android:name="android.permission.INTERNET"/>
1

Guess you like

Origin www.cnblogs.com/ly570/p/11498542.html