To show a WebView progress bar, put a horizontal ProgressBar above the WebView, set a WebChromeClient, and override onProgressChanged. Android passes that method the page loading progress as a number from 0 to 100. Push the number into the bar and hide the bar when it reaches 100.
Why a WebView app needs its own progress bar
A WebView shows the page and nothing else, so the loading line you know from a browser is missing. Tap a link on a slow connection and the screen sits still until the next page paints. People tap again, or decide the app froze.
What you need before you start
You need a WebView that already loads your site and two client objects on it. They do different jobs, and mixing them up is the classic mistake here.
Android’s WebView guide says WebViewClient is for “handling events that impact content rendering, such as errors on form submissions or navigation.” WebChromeClient covers the browser-style interface around the page. Progress belongs to the second one.
The WebChromeClient reference describes onProgressChanged as “Tell the host application the current progress of loading a page.” Its newProgress value is “an integer between 0 and 100.”
How to add a WebView progress bar, step by step
Adding a WebView progress bar takes three steps: place the bar, feed it the progress, hide it when the page is done. This is the Kotlin version for a classic View layout.
- Put a horizontal bar above the WebView. A plain
ProgressBarstarts as a spinner. The ProgressBar reference says “Indeterminate mode is the default,” so set the horizontal style to get a line that fills.
<ProgressBar
android:id="@+id/progress"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="Page loading"
android:visibility="gone" />
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
- Send the progress to the bar. The same reference says “the progress bar is full when the progress value reaches 100.” The WebView uses the same scale, so no conversion is needed.
val bar = findViewById<ProgressBar>(R.id.progress)
val webView = findViewById<WebView>(R.id.webview)
webView.webChromeClient = object : WebChromeClient() {
override fun onProgressChanged(view: WebView, newProgress: Int) {
bar.progress = newProgress
bar.visibility = if (newProgress < 100) View.VISIBLE else View.GONE
}
}
- Keep your WebViewClient as it is. Links, errors and URL handling stay there.
Every new page load starts low and climbs, so the same if line brings the bar back on each link tap.
How to check the progress bar works
Check the progress bar on a real phone with the network slowed down, because on fast Wi-Fi the bar is gone before you see it.
Open the app and watch the bar fill from left to right, then vanish. Tap a link to another page. It should come back and go again.
Then turn on flight mode and tap a link. The bar must not stay on screen over the error page. If it does, the next section covers why.
Why the progress bar gets stuck or never shows
A stuck or missing progress bar almost always comes from driving it with the wrong callback. Many older tutorials show the bar in onPageStarted and hide it in onPageFinished. The WebViewClient reference documents three limits that break this pattern.
| Callback | Documented behaviour | What it does to your bar |
|---|---|---|
onPageStarted |
Not called “for fragment navigations (navigations to #fragment_id)” | Anchor links never show a bar |
onPageFinished |
“does not guarantee that the next frame drawn by WebView will reflect the state of the DOM at this point” | The bar can hide before the page is visible |
onReceivedError |
The current version “will be called for any resource (iframe, image, etc.), not just for the main page” | Hiding the bar here hides it for one broken image |
The other common cause is an override in the wrong class. Put onProgressChanged inside your WebViewClient and the code compiles in Java without @Override, but nothing ever calls it.
A bar that spins forever is usually still in indeterminate mode. Check the style from step 1.
Use the Material progress indicator for a cleaner bar
Material’s LinearProgressIndicator is a drop-in replacement that looks better and handles flicker. The component documentation says determinate indicators “fill from 0% to 100%. Use it when progress and wait time is known.” That fits a page load.
Swap the widget in the layout, then set the value with the animated call:
indicator.setProgressCompat(newProgress, true)
Two attributes solve the flash you get on fast pages. app:showDelay waits before showing the indicator, and app:minHideDelay keeps it on screen for a minimum time once shown. Both default to 0, so they do nothing until you set them. The track is 4dp thick by default, which you can change with app:trackThickness.
The same documentation says: “Please consider setting the content descriptor for use with screen readers.” The android:contentDescription attribute in step 1 does that.
Show WebView progress in Jetpack Compose
In Compose, the progress indicator uses a different scale from the WebView, so you divide. The Compose progress guide says of the progress parameter: “Pass a Float between 0.0 and 1.0.”
Keep the WebView’s number in state and convert it:
var progress by remember { mutableIntStateOf(0) }
if (progress < 100) {
LinearProgressIndicator(progress = { progress / 100f })
}
Update progress from the same onProgressChanged override. If you leave the progress parameter out, Compose draws an indeterminate indicator instead.
Spinner or horizontal bar?
Use a horizontal bar for page loads and keep the spinner for waits you can’t measure. The ProgressBar reference says to use indeterminate mode “when you do not know how long an operation will take.”
My take: a thin bar at the top beats a full-screen spinner in a WebView app. A spinner over the whole page hides content that has already arrived, and every link tap feels slower than it is. A full-screen wait belongs on the first launch only, which is a job for a splash screen.
What the progress bar can’t tell you
The progress value only covers real page loads. If your site is a single-page app that swaps views with JavaScript, no new main frame load starts, and the WebView has nothing to report. Your site has to show its own loading state for those moments.
The number also isn’t a time estimate. A page can sit near the end while one slow script finishes.
Do you have to code this yourself?
Not always. Apps generated with my own tool, WebToAPK Free, come with a loading bar in the app runtime, along with refresh and menu icons in the top bar and an error screen with a Try again button. If you built your app before that runtime update, rebuild it to get the bar.
After the bar, add pull to refresh, decide what the app shows without internet, and learn the usual causes of a white screen. Together they also help with Google Play’s minimum functionality rule.
FAQ
Which callback gives the WebView loading progress?
onProgressChanged in WebChromeClient. Android calls it with the current page loading progress as an integer between 0 and 100. It is not a WebViewClient method, so an override placed there never runs.
Why does my WebView progress bar never disappear?
Usually the hide logic sits in the wrong callback or the bar was left in indeterminate mode. Hide the bar inside onProgressChanged when the value reaches 100, and don’t depend on onPageFinished or onReceivedError alone.
Should I use a spinner or a horizontal bar?
Use a horizontal determinate bar when you have a real progress value, which a WebView gives you. A spinner fits waits where progress is unknown, such as the first launch before any page has started.
Does the progress bar work for single-page sites?
Only for real page loads. Route changes that a single-page site handles in JavaScript, and jumps to an anchor on the same page, don’t start a new main frame load, so the WebView reports nothing for them.
Sources
- WebChromeClient API reference, Android Developers
- WebViewClient API reference, Android Developers
- ProgressBar API reference, Android Developers
- Progress indicators, Material Components for Android
- Progress indicators in Jetpack Compose, Android Developers
- Build web apps in WebView, Android Developers