Skip to content

WebView

implementation("androidx.webkit:webkit:1.8.0")

In project explorer under main/assets add a HTML file, then use loadUrl("file:///android_asset/...") to locate it.

NOTE: file:///android_asset points to main/assets

AndroidView(factory = {
WebView(it).apply {
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, // for style width and height
ViewGroup.LayoutParams.MATCH_PARENT
)
}
}, update = {
it.loadUrl(<file-path or web url>)
})

To access the internet, enable the permission in AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET" />