Skip to content
Related Articles

Related Articles

How to use WebView in Android
  • Last Updated : 18 Feb, 2021
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 javascipt.
        // 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"

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :