Android Webview Load website and local HTML file
<WebView
android:id="@+id/webViewOffline"
android:visibility="visible"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<WebView
android:id="@+id/webViewOnline"
android:visibility="visible"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
// Load a local HTML file
val webViewOffline: WebView = findViewById(R.id.webViewOffline)
webViewOffline.webViewClient = WebViewClient()
webViewOffline.settings.javaScriptEnabled = true
webViewOffline.loadUrl("file:///android_asset/location.html")
// Load a URL
val webViewOnline: WebView = findViewById(R.id.webViewOnline)
webViewOnline.webViewClient = WebViewClient()
webViewOnline.settings.javaScriptEnabled = true
webViewOnline.loadUrl("https://www.htmlhero.xyz")
Create assets directory and keep local html files in this
Add Permission on Manifest
<uses-permission android:name="android.permission.INTERNET" />
Comments
Post a Comment