Signup/Sign In

Android WebView

Android WebView is used to load and display the web pages in android.

A WebView is useful when we need to increase control over the UI and advanced configuration options in our app.

Here, we will learn to add an Android WebView in our android app. So, let's get started.

Step 1: Create a new Project

  1. Open Your Android Studio Click on "Start a new Android Studio project"(Learn how to set up Android Studio and create your first Android project)

  2. Choose "Empty Activity" from the project template window and click on Next.

  3. Enter the App Name, Package name, save location, language(Java/Kotlin, we will use Java for this tutorial), and the minimum SDK(we are using API 19: Android 4.4 (KitKat))

  4. Next click on the Finish button after filling in the above details.

  5. Now, wait for the project to finish building.

Step 2: Adding the Internet Permission

Now go to app -> mainfests-> AndroidManifest.xml and add internet permission, now our AndroidManifest.xml file will look like as shown below:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    <uses-permission android:name="android.permission.INTERNET"/>
        <activity android:name=".MainActivity">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />

Step 3: Adding WebView to Android Activity

Now go to app -> res -> layout -> activity_main.xml and add Webview, now our activity_main.xml file will look like as shown below:

<?xml version = "1.0" encoding = "utf-8"?>
<RelativeLayout xmlns:android = ""
    xmlns:app = ""
    xmlns:tools = ""
    android:layout_width = "match_parent"
    android:layout_height = "match_parent"
    tools:context = ".MainActivity">

    <!-- webview -->

In the above code, we have added the default web view in our Android Activity.

Step 4: Modify activity_main.xml

This is the main part to add webview in our app, first, we open the file and import some basic classes as shown below

import android.os.Bundle;
import android.webkit.WebView;

Next, we create the object of WebView class inside MainActivity class as shown below:

//creating object of WebView
WebView oklWebView;

Now, inside the onCreate method, we initialize the WebView as shown below.

//initializing the WebView objects

After initializing the webview, we simply load the URL.

 //load the url

The complete code of the is shown below:

package com.studytonight.project;

import android.os.Bundle;
import android.webkit.WebView;

public class MainActivity extends AppCompatActivity {

    //creating object of WebView
    WebView oklWebView;
    protected void onCreate(Bundle savedInstanceState) {

        //initializing the WebView objects

        //load the url

Now, our app is ready, run the app and see the the output.


In the below snapshots, you can see how Webview will look in the android application.

When the app is opened for the first time: We can see that the is opened in our app

When Scrolling the webview, it goes bottom to the page.

About the author:
K S Lohan is an accomplished author and expert in technical writing on Android language and develop android App. He is highly skilled at communicating complex programming concepts in a clear and concise manner.