Load static html code in WebView
Description
The following code shows how to load static html code in WebView.
Example
Layout xml
<?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/webkit"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
Java code
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
/*from w ww . ja v a 2s . co m*/
public class MainActivity extends Activity {
WebView browser;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
browser=(WebView)findViewById(R.id.webkit);
browser.loadData("<html><body>Hello, world!</body></html>",
"text/html", "UTF-8");
}
}