WebViewネットワークビュー
2557 ワード
public class Main 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.webview);
/* */
// String URL="http://www.baidu.com/";
// webView.loadUrl(URL);
/* HTML */
// String html = "";
// html += "<html>";
// html += "<body>";
// html += "<a href=http://www.baidu.com/>Baidu</a>";
// html += "</body>";
// html += "</html>";
//
// webView.loadData(html, "text/html", "utf-8");
/* SDCard */
String htmlPath = "file:///sdcard/test/test.html";
String html = "<html xmlns=" + "http://www.w3.org/1999/xhtml" + ">";
html += "<head>";
html += "<meta http-equiv=" + "Content-Type" + " content="
+ "text/html; charset=utf-8" + " />";
html += "<title> </title>";
html += "</head>";
html += " <img src=" + "1.jpg" + ">";
html += "<body></body></html>";
String baseUrl = "file:///sdcard/test/";
webView.loadDataWithBaseURL(baseUrl, html, "text/html", "utf-8", null);
/* SDCard HTML */
// String htmlPath = "file:///sdcard/test/test.html";
// String baseUrl = "file:///sdcard/test/";//
// webView.loadDataWithBaseURL(baseUrl, html, "text/html", "utf-8",
// null);
// webView.loadUrl(htmlPath);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</WebView>
</LinearLayout>