\
\
Load the URI directly using the WebView, and it will appear that the system’s browser is called to access the URI
package com.example.webviewdemo;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class MainActivity extends Activity {
WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webView1);
// If added directly to the URI
webView.loadUrl("http://www.baidu.com"); }}Copy the code
The main layout:
<span style="font-size:18px;"><RelativeLayout 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"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<WebView
android:layout_below="@+id/textView1"
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignLeft="@+id/textView1" />
</RelativeLayout></span>
Copy the code
Take a look at the results:
\
Use the WebView’s own loading method:
\
Look at the effect: the browser is not called to load the URI, but the WebView itself
Loading mode. You can see that the URI data is displayed in the webView, not in the browser.
\
\
\