How to Use WebView in Android? Last Updated : 28 Jan, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report WebView is a view that displays web pages as a part of the application layout. It is used to embed a complete website into an app.public class WebView extends AbsoluteLayout implements ViewTreeObserver.OnGlobalFocusChangeListener, ViewGroup.OnHierarchyChangeListenerClass Hierarchy:java.lang.Object ↳ android.view.View ↳ android.view.ViewGroup ↳ android.widget.AbsoluteLayout ↳ android.webkit.WebViewStep by Step ImplementationStep 1: Create a New Project in Android StudioTo create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note: The code for that has been given in both Java and Kotlin Programming Language for Android.Step 2: Adding Permissions to the AndroidManifest.xml FileIn AndroidManifest.xml, one needs to include the below permission, in order to access the Internet.<uses-permission android:name="android.permission.INTERNET"/>Step 3: Working with the MainActivity FileGo to the MainActivity File and refer to the following code. Below is the code for the MainActivity File. Comments are added inside the code to understand the code in more detail.MainActivity: Java import android.os.Bundle; import android.webkit.WebView; import android.webkit.WebViewClient; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Find the WebView by its unique ID WebView webView = findViewById(R.id.web); // loading https://www.geeksforgeeks.org url in the WebView. webView.loadUrl("https://write.geeksforgeeks.org"); // this will enable the javascript. webView.getSettings().setJavaScriptEnabled(true); // WebViewClient allows you to handle // onPageFinished and override Url loading. webView.setWebViewClient(new WebViewClient()); } } Kotlin package org.geeksforgeeks.demo import android.os.Bundle import android.webkit.WebView import android.webkit.WebViewClient import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Find the WebView by its unique ID val webView = findViewById<WebView>(R.id.web) // loading http://www.google.com url in the WebView. webView.loadUrl("https://write.geeksforgeeks.org") // this will enable the javascript. webView.settings.javaScriptEnabled = true // WebViewClient allows you to handle // onPageFinished and override Url loading. webView.webViewClient = WebViewClient() } } Step 4: Working with the XML FilesNext, go to the activity_main.xml file, which represents the UI of the project. Below is the code for the activity_main.xml file. Comments are added inside the code to understand the code in more detail.activity_main.xml: XML <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <WebView android:id="@+id/web" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"/> </androidx.constraintlayout.widget.ConstraintLayout> Output: Comment More infoAdvertise with us Next Article How to Use WebView in Android? A AnushkaKhattri Follow Improve Article Tags : Android Kotlin Android Android-View Java-Android Similar Reads Android Architecture Android architecture contains a different number of components to support any Android device's needs. Android software contains an open-source Linux Kernel having a collection of a number of C/C++ libraries which are exposed through application framework services. Among all the components Linux Kern 5 min read Android Tutorial In this Android Tutorial, we cover both basic and advanced concepts. So whether you are a fresher (graduate) or an experienced candidate with several years of Android Development experience, you can follow this Android tutorial to kick-start your journey in Android app development. Our Android Tutor 15+ min read Activity Lifecycle in Android with Demo App In Android, an activity is referred to as one screen in an application. It is very similar to a single window of any desktop application. An Android app consists of one or more screens or activities. Each activity goes through various stages or a lifecycle and is managed by activity stacks. So when 9 min read Introduction to Android Development Android operating system is the largest installed base among various mobile platforms across the globe. Hundreds of millions of mobile devices are powered by Android in more than 190 countries of the world. It conquered around 71% of the global market share by the end of 2021, and this trend is grow 5 min read Top 50 Android Interview Questions and Answers - SDE I to SDE III A Linux-based open-source OS, Android was created by Andy Rubin and became one of the most popular smartphone operating systems. With 71 percent of the market share worldwide, Android is on top. Because it is on top in the smartphone OS, Android development is always in demand.If you are seeking a j 15+ min read Android UI Layouts Layouts in Android define the user interface and hold UI controls or widgets that appear on the screen of an application. Every Android application consists of View and ViewGroup elements. Since an application contains multiple activitiesâeach representing a separate screenâevery activity has multip 5 min read Top 50 Flutter Interview Questions and Answers for 2025 Flutter is an open-source, cross-platform application development framework. It was developed by Google in 2017. It is used to build applications for Android, iOS, Linux, Mac, Windows, and the web. Flutter uses the Dart programming language. It provides a simple, powerful, efficient, and easy-to-und 15+ min read Components of an Android Application There are some necessary building blocks that an Android application consists of. These loosely coupled components are bound by the application manifest file which contains the description of each component and how they interact. The manifest file also contains the appâs metadata, its hardware confi 3 min read Android Studio Tutorial It is stated that "If you give me six hours to chop down a tree then I will spend the first four hours in sharpening the axe". So in the Android Development World if we consider Android Development as the tree then Android Studio should be the axe. Yes, if you are starting Android Development then y 9 min read MVVM (Model View ViewModel) Architecture Pattern in Android Developers always prefer clean and structured code for projects. Organizing the codes according to a design pattern helps in the maintenance of the software. By having knowledge of all crucial logic parts of the android application, it is easier to add and remove app features. Further, design patter 8 min read Like