WEB开发网
开发学院手机开发Android 开发 Android——WebView组件的使用详解 阅读

Android——WebView组件的使用详解

 2010-07-22 09:19:00 来源:WEB开发网   
核心提示:通过本专题的讲解可以了解到WebView组件的详细使用:网络内容1、LoadUrl直接显示网页内容(单独显示网络图片)2、LoadData显示中文网页内容(含空格的处理)APK包内文件1、LoadUrl显示APK中Html和图片文件2、LoadData(loadDataWithBaseURL)显示APK中图片和文字混合

通过本专题的讲解可以了解到WebView组件的详细使用:

网络内容

1、LoadUrl直接显示网页内容(单独显示网络图片)

2、LoadData显示中文网页内容(含空格的处理)

APK包内文件

1、LoadUrl显示APK中Html和图片文件

2、LoadData(loadDataWithBaseURL)显示APK中图片和文字混合的Html内容

res/layout/main.xml

Xml代码

< ?xml version="1.0" encoding="utf-8"?>

< LINEARLAYOUT android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/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="http://schemas.android.com/apk/res/android">

< WEBVIEW android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="@+id/webview" />

< /LINEARLAYOUT>

Example_webview.java

Java代码

package cn.coolworks;

import java.net.URLEncoder;

import android.app.Activity;

import android.os.Bundle;

import android.webkit.WebView;

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) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

webView = (WebView) findViewById(R.id.webview);

webView.getSettings().setJavaScriptEnabled(true);

1 2 3  下一页

Tags:Android WebView 组件

编辑录入:coldstar [复制链接] [打 印]
赞助商链接