DEV Community

rrtutors
rrtutors

Posted on • Originally published at rrtutors.com

How to load html page with jetpack compose?

Jetpack compose webview How to load html page with jetpack compose in Android application using Jetpack Compose.

Jetpack compose doesn't have any direct compose functions to load html/web content. For this we will use AndroidView compose function which will load views. So to load html content we will use Webview view inside AndroidView compose API

Render this html page using Webview

We know that Webview is an subclass of a View through which we can load different web pages.

Lets Add a WebView inside AndroidView where Android View is used to to render views that are not avaiable in Compose.

AndroidView(factory = {
  WebView(context).apply {
  webViewClient = WebViewClient()
  loadDataWithBaseURL(null, htmlPage, "text/HTML", "UTF-8", null)
}
})
Enter fullscreen mode Exit fullscreen mode

In the above code we loaded html content inside webview, similarly we can also load webpages as like android webview widget.
Jetpack compose load html content

Download complete code for Jetpack compose Webview example

Discussion (0)