通过本专题的讲解可以了解到WebView组件的详细使用:
网络内容
1、LoadUrl直接显示网页内容(单独显示网络图片)
2、LoadData显示中文网页内容(含空格的处理)
APK包内文件
1、LoadUrl显示APK中Html和图片文件
2、LoadData(loadDataWithBaseURL)显示APK中图片和文字混合的Html内容
res/layout/***
Xml代码
< ?xml version="1.0" encoding="utf-8"?>
< LINEARLAYOUT android:layout_height="fill_parent" android:layout_width="fill_parent"android:orientation="vertical" xmlns:android="***/res/android">
< WEBVIEW android:layout_height="fill_parent" android:layout_width="fill_parent"android:id="@+id/webview" />
< /LINEARLAYOUT>
< ?xml version="1.0" encoding="utf-8"?>
< LINEARLAYOUT android:layout_height="fill_parent" android:layout_width="fill_parent"android:orientation="vertical" xmlns:android="***/res/android">
< WEBVIEW android:layout_height="fill_parent" android:layout_width="fill_parent"android:id="@+id/webview" />
< /LINEARLAYOUT>
Example_***
Java代码
package ***rks;
import ***oder;
import ***ty;
import ***;
import ***w;
public class Example_webview extends Activity {
WebView webView;
final String mimeType = "text/html";
final String encoding = "utf-8";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
***te(savedInstanceState);
setContentView(***);
webView = (WebView) findViewById(***w);
***tings().setJavaScriptEnabled(true);