Load local resource into WebView : WebView « UI « Android






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

1.Adding WebView to Activity, load URL and grab focus
2.Enable Javascript for WebView
3.Load remote web page for WebView
4.extends WebViewClient and check the url
5.Using WebView to load url
6.Using WebView to load static html string
7.Load static html file into WebView
8.Load Url to WebView
9.Load image from remote host to WebView
10.Add a client to the web view
11.Sample creating 10 webviews.