Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

How to Display Progress in ProgressBar While Loading URL in WebView in Android?

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

ProgressBar in Android is a UI element that displays the status of some work being done in the background in the form of some animation. It can be anything, like computing, loading, searching, fetching, downloading, etc. ProgressBar broadly has two types namely spinning wheel and horizontal bar. 

Spinning Wheel ProgressBar

Horizontal ProgressBar

In this article, we want to show you how you could implement a ProgressBar in Android and display it until a specific webpage is loading.

Step by Step Implementation

Step 1: Create a New Project in Android Studio

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. We demonstrated the application in Kotlin, so make sure you select Kotlin as the primary language while creating a New Project.

Step 2: Add Internet permission in the Manifest file (AndroidManifest.xml)

To load a web page, we would require our application to use the Internet. So we need to add permission to use the internet.


<?xml version="1.0" encoding="utf-8"?>
    <uses-permission android:name="android.permission.INTERNET"/>

Step 3: Add a ProgressBar and a WebView in the layout file (activity_main.xml)


<?xml version="1.0" encoding="utf-8"?>
        android:progress="100" />
        android:layout_marginTop="5dp" />

Step 4: Add this in the Main code (MainActivity.kt)

Refer to the comments for better understanding.


import android.os.Bundle
import android.view.View
import android.webkit.WebView
import android.widget.ProgressBar
class MainActivity : AppCompatActivity() {
    // Declaring webView and progressBar
    private lateinit var webView: WebView
    lateinit var progressBar: ProgressBar
    override fun onCreate(savedInstanceState: Bundle?) {
        // Initializing Webview and 
        // progressBar from the layout file
        webView = findViewById(
        progressBar = findViewById(
        // Setting a webViewClient
        webView.webViewClient = WebViewClient()
        // Loading a URL
    // Overriding WebViewClient functions
    inner class WebViewClient : android.webkit.WebViewClient() {
        // Load the URL
        override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
            return false
        // ProgressBar will disappear once page is loaded
        override fun onPageFinished(view: WebView, url: String) {
            super.onPageFinished(view, url)
            progressBar.visibility = View.GONE


You can see a progress bar running just before the page loads. Once the page loads, the progress bar disappears.

P.S: Watch the output at a speed lower than normal.

My Personal Notes arrow_drop_up
Last Updated : 29 Jul, 2021
Like Article
Save Article
Similar Reads