\
\
直接使用WebView加载uri, 会出现,调用系统的浏览器来访问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);
//如果直接加在uri
webView.loadUrl("http://www.baidu.com");
}
}
主布局:
<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>
来看一下效果:
\
使用WebView自己的加载方式:
\
看下效果:并没有调用浏览器来加载uri,而是WebView自己的
加载方式。 可以看到哦uri数据显示在webView中,而不是在浏览器中。
\
\
\