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.

         WebView mywebview = (WebView) findViewById(;

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.

        WebView mywebview = (WebView) findViewById(;

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

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

Android WebView Example

Let’s see a simple example of android webview.


File: activity_main.xml
<?xml version=“1.0” encoding=“utf-8”?>
< xmlns:android=“”
        app:layout_constraintTop_toTopOf=“parent” />

To add the web page (.html, .jsp) locally in application, they are required to place in the assets folder. An assets folder is created as: right click on app -> New -> Folder -> Assets Folder ->main or simply create an assets directory inside main directory.

Activity class

import android.os.Bundle;
import android.webkit.WebView;
public class MainActivity extends AppCompatActivity {
    protected void onCreate(Bundle savedInstanceState) {
        WebView mywebview = (WebView) findViewById(;
        // mywebview.loadUrl(“”);
        /*String data = “<html><body><h1>Hello, Javatpoint!</h1></body></html>”;
        mywebview.loadData(data, “text/html”, “UTF-8”); */


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

android webview example output 1

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

android webview example output 2