android訪問html頁面

Activity代碼以下:html

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頁面路徑:java

\reg\assets\index.html   \reg 爲項目名稱
android

HTML代碼以下:web

<!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>
相關文章
相關標籤/搜索