import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class HtmlViewActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView webview = (WebView) findViewById(R.id.webView1);
String data = "<html><head><meta http-equiv=\"content-type\" content=\"text/html;charset=UTF-8\"></head>";
data += "<body>HTML データを作って表示</body></html>";
webview.loadData(data, "text/html", "UTF-8");
}
}
JavaScript を含める場合
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class HtmlViewActivity extends Activity {
private WebView webview;
private String html;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
webview = new WebView(this);
html = "<html><head><meta http-equiv=\"content-type\" content=\"text/html;charset=UTF-8\">";
html += "<script type=\"text/javascript\"> document.write('JavaScriptで表示<br />');</script>";
html += "</head>";
html += "<body>HTML データを作って表示</body></html>";
// JavaScriptを有効にする
webview.getSettings().setJavaScriptEnabled(true);
//ページを読み込み
webview.loadData(html, "text/html", "UTF-8");
setContentView(webview);
}
}

0 件のコメント:
コメントを投稿