Activity代码如下:
package com.example.reg;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
public class WebViewActivity extends Activity{
private static final String tag = WebViewActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
WebView webview = (WebView) findViewById(R.id.web_view);
webview.getSettings().setJavaScriptEnabled(true);
//webview.loadUrl("http://www.baidu.com");
//用file://来指定本地文件
webview.loadUrl("file:///android_asset/html/test.html");
Log.d(tag, "执行结束..");
}
}
html页面路径:
\reg\assets\index.html \reg 为项目名称
HTML代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Hello First Html..</title>
</head>
<body>
First Html
</body>
</html>