Android Webview Example
Android Webview Example
Android AlertDialog class is used to display a web page embedded in the Android Activity. The web page could
be displayed in the same Android Application, without opening a browser window.
WebView could be used in your Android Application like any other View (say TextView, Button, etc.).
1. Add permission for INTERNET in AndroidManifest.xml. Applications that make use of WebView require INTERNET
permission. To let Android know that our application require INTERNET, include the following line in
AndroidManifest.xml. <uses-permission android:name="android.permission.INTERNET" />
2. Include Android WebView In layout fileYou can include following WebView snippet in Layout file to display WebView in
Activity.
AndroidManifest.xml
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tutorialkart.webviewexample">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EEE"
tools:context=".MainActivity">
<TextView
android:text="Web View Example"
android:gravity="center"
android:padding="20sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<WebView
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
MainActivity.kt
package com.tutorialkart.webviewexample
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*
webView.loadUrl("https://www.google.com/")
}
}
Conclusion
In this Kotlin Android Tutorial – AlertDialog Example, we have learnt to display an Alert Dialog box in Activity.
We also learnt to set title, message and Positive, Negative buttons of AlertDialog.
Kotlin vs Java
Android TextView
Android Button
Android Toast
Android EditText
Android ImageView
Android SeekBar
Android Intent
Android - Start Another Activity
Android AlertDialog
Android WebView
Android ProgressBar
Android Snackbar
Android ListView
Android Canvas
Android runOnUiThread
Fix Errors
Android - All support libraries must use the exact same version specification
Example Applications
Kotlin - Java
Kotlin Tutorial
Useful Resources