Android Webview Tutorial With Example

Have you seen the Android app displaying Web content using Webview. This Android Webview Tutorial is about Webview. Webview is an extension of Android’s View that allows users to display a website as part of the activity.

You can also use Webview in your application. And if you want to use it in your app so in this post i will guide you about implementing Webview in an Android application.

Create a new project

  • As for every new application we need to create a new Android Studio project. For this i have created a new project
  • After creating new project we need to add internet permission todo so add the below line in your AndroidManifest.xml just above your Application tag
<uses-permission android:name="android.permission.INTERNET"/>

We need the internet to display web content in WebView, so for accessing the internet we added the above permission in our AndroidManifest.xml.

Implementation of Webview

 Android Webview layout

   Open res/layout/activity_main.xml and write the following code

<LinearLayout xmlns:android=""



The Android Webview component is added into the layout file in which we want to display Webview.

Android Webview code

Open and initialize Webview using its id defined in activity_main.xml as shown in the snippet below.

WebView myWebView = findViewById(;

Android Webview loadUrl

  Once the Webview reference is obtained we can load Urls by using the Webview loadUrl() method


Before loading Url there is one thing we need to take a look at, And that is Supporting JavaScript in webview.

By default the JavaScript is turned off in webview so the pages containing javaScript won’t load perfectly. So the following snippet will be called to enable javaScript.


Complete containing all the features discussed above.

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

public class MainActivity extends AppCompatActivity {

   protected void onCreate(Bundle savedInstanceState) {

       WebView myWebView = findViewById(;

       myWebView.loadUrl("");//url loading

Now run your app and change the Url with your own, if you have any question then comment below.