Skip to content
Related Articles

Related Articles

How to use WebView in Android

View Discussion
Improve Article
Save Article
Like Article
  • Difficulty Level : Medium
  • Last Updated : 04 Jan, 2022
public class WebView 
extends AbsoluteLayout 

WebView is a view that display web pages inside the application. It is used to turn the application into a web application.

Class Hierarchy :

   ↳  android.view.View
        ↳  android.view.ViewGroup
             ↳  android.widget.AbsoluteLayout
                  ↳  android.webkit.WebView


package com.example.hp.webview;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
    protected void onCreate(Bundle savedInstanceState) {
        // Binding with 
        // activity_main.xml file
        // Find the WebView by its unique ID
        WebView w = (WebView) findViewById(;
        // loading url in the the WebView.
        // this will enable the javascript.
        // WebViewClient allows you to handle 
        // onPageFinished and override Url loading.
        w.setWebViewClient(new WebViewClient());


In the xml file only use of WebView is made inside RelativeLayout.


<?xml version="1.0" encoding="utf-8"?>
        <!-- covers 368dp width as required. -->
        <!-- unique ID of WebView -->
        <!-- covers 495dp height as required. -->
        tools:layout_editor_absoluteY="8dp" />

In AndroidManifest.xml, one needs to include below permission, in order to access internet:

"uses-permission android:name="android.permission.INTERNET"

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!