What is a WebView?

In short
A WebView is an Android view that displays a web page inside your app. It works like a small, built-in browser window placed in your screen layout, without browser controls such as an address bar. It is useful for content that changes often or for data that needs an internet connection.
What a WebView does
A WebView is a component from Android's android.webkit package. It extends the View class, so you can place it in an activity layout just like a button or a text field. Its job is to show a web page. By default, it does nothing more. It has no address bar, no back button and no navigation controls, so you decide how the user moves around.
This makes it handy when your app needs to show content that is hosted on the web. A common example is an end-user agreement or a user guide. You can update the page on your server, and the app shows the new version without a new release.
When to use it
WebView also fits screens that show data from the internet. Imagine a screen that lists a user's messages. You could fetch the data over the network, parse it, and build native layouts for every item. Or you could build a web page designed for Android devices and let a WebView load it. The second route often needs less code, because the layout lives in the web page.
The trade-off is that a WebView does not look or feel exactly like native Android interface elements. Use it where web content is the right tool, and keep fast or highly interactive screens native.
A simple example
First, your app needs permission to use the internet. Add this line to your manifest file:
Next, add a WebView to your activity layout:
Finally, load a page from your activity code. In Kotlin, it looks like this:
val myWebView: WebView = findViewById(R.id.webview) myWebView.loadUrl("http://www.example.com")
You can also build the WebView in code inside onCreate(), attach it with setContentView(), and then call loadUrl() on it. The documentation also shows how to load an HTML string by encoding it with base64 and calling loadData().
Turning on JavaScript
JavaScript is disabled in a WebView by default. If your page needs it, turn it on through the WebSettings object. You get WebSettings with getSettings(), then call setJavaScriptEnabled(true). Enable it only when you need it, and only for pages you trust.
WebSettings also controls other behavior, such as a custom user agent string. A custom user agent lets your web page check that the request comes from your Android app.
Common mistakes
The most common problem is forgetting the INTERNET permission. The page then fails to load, and the WebView stays blank. Check the manifest first.
Another mistake is expecting links to open inside the WebView. By default, when a user taps a link, Android opens a app that handles URLs, usually the browser. To keep links in your WebView, set a WebViewClient with setWebViewClient(). To control which links stay in the app, override shouldOverrideUrlLoading() and return false for pages on your own site.
Finally, remember that a WebView is not a full browser. If you need features such as tabs or downloads, you must build them yourself.
Alternatives
If you only need to open a link in the user's browser, an Intent is simpler and does not embed any page in your screen. If your data comes from an API and you want native screens, fetching the data and rendering it with Android views is the better fit. For two-way communication between web code and native code, the documentation also points to newer, more secure approaches, such as the JSBridge pattern described in the Access native APIs with JSBridge guide.
A WebView is a practical tool. Use it when web content is the natural source, and keep the boundaries between your web code and your app code clear.
FAQ
Is a WebView the same as a web browser app?
No. A WebView shows web pages inside your own app, but it has no address bar or navigation controls. Your app decides what the user can do on the page.
Why does my WebView show a blank screen?
The most common cause is a missing INTERNET permission in the manifest file. Also check that you called loadUrl() or loadData() after the WebView was created.
Is JavaScript enabled in a WebView by default?
No. You must turn it on by calling setJavaScriptEnabled(true) on the WebSettings object that you get from getSettings().
Can I open links in the default browser instead of the WebView?
Yes. Override shouldOverrideUrlLoading() in a WebViewClient and start an Intent with ACTION_VIEW for links that are not on your own site.
Sources
This page is based on the official documentation below. Read it for full detail.
WebView — official documentation ↗