Load local resource into WebView
package app.test;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class Test extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView upperView = (WebView)findViewById(R.id.upperview);
upperView.getSettings().setBuiltInZoomControls(true);
upperView.loadUrl("file:///android_asset/android.jpg");
WebView lowerView = (WebView)findViewById(R.id.lowerview);
String htmlString =
"<h1>Header</h1><p>This is HTML text<br /><i>Formatted in italics</i></p>";
lowerView.loadData(htmlString, "text/html", "utf-8");
}
}
//main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<WebView
android:id="@+id/upperview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
/>
<WebView
android:id="@+id/lowerview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
/>
</LinearLayout>
Related examples in the same category