Cheap VPS & Xen Server

Residential Proxy Network - Hourly & Monthly Packages


Android WebView is used to display web page in android. The web page can be loaded from same application or URL. It is used to display online content in android activity.

Android WebView uses webkit engine to display web page.

The android.webkit.WebView is the subclass of AbsoluteLayout class.

The loadUrl() and loadData() methods of Android WebView class are used to load and display web page.


Let’s see the simple code to display web page using web view.

  1. WebView mywebview = (WebView) findViewById(;
  2. mywebview.loadUrl(“”);

Let’s see the simple code to display HTML web page using web view. In this case, html file must be located inside the asset directory.

  1. WebView mywebview = (WebView) findViewById(;
  2. mywebview.loadUrl(“file:///android_asset/myresource.html”);

Let’s see another code to display HTML code of a string.

  1. String data = “<html><body><h1>Hello, Kreationnext!</h1></body></html>”;
  2. mywebview.loadData(data, “text/html”“UTF-8”);

Android WebView Example

Let’s see a simple example of android webview.


File: activity_main.xml
  1. <RelativeLayout xmlns:android=“”
  2.     xmlns:tools=“”
  3.     android:layout_width=“match_parent”
  4.     android:layout_height=“match_parent”
  5.     tools:context=“.MainActivity” >
  6.     <WebView
  7.         android:id=“@+id/webView1”
  8.         android:layout_width=“match_parent”
  9.         android:layout_height=“match_parent”
  10.         android:layout_alignParentTop=“true”
  11.         android:layout_centerHorizontal=“true”
  12.         android:layout_marginTop=“42dp” />
  13. </RelativeLayout>

Activity class

  1. package com.example.webview;
  2. import android.os.Bundle;
  3. import;
  4. import android.view.Menu;
  5. import android.webkit.WebView;
  6. public class MainActivity extends Activity {
  7.     @Override
  8.     protected void onCreate(Bundle savedInstanceState) {
  9.         super.onCreate(savedInstanceState);
  10.         setContentView(R.layout.activity_main);
  11.         WebView mywebview = (WebView) findViewById(;
  12.          //mywebview.loadUrl(“”);
  13.         /*String data = “<html><body><h1>Hello, Kreationnext!</h1></body></html>”;
  14.         mywebview.loadData(data, “text/html”, “UTF-8”); */
  15.         mywebview.loadUrl(“file:///android_asset/myresource.html”);
  16.     }
  17.     @Override
  18.     public boolean onCreateOptionsMenu(Menu menu) {
  19.         // Inflate the menu; this adds items to the action bar if it is present.
  20.         getMenuInflater().inflate(, menu);
  21.         return true;
  22.     }
  23. }


Let’s see the output if you load the HTML page.


Let’s see the output if you load the web page.