fahad005

WebView (kotlin)

Oct 27th, 2021
859
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.firstapplication
  2.  
  3. import androidx.appcompat.app.AppCompatActivity
  4. import android.os.Bundle
  5. import android.webkit.WebViewClient
  6. import androidx.databinding.DataBindingUtil
  7. import com.example.firstapplication.databinding.ActivityMainBinding
  8.  
  9. class MainActivity : AppCompatActivity() {
  10.  
  11.     override fun onCreate(savedInstanceState: Bundle?) {
  12.         super.onCreate(savedInstanceState)
  13.         setContentView(R.layout.activity_main)
  14.  
  15.         // this part
  16.         var bind : ActivityMainBinding? = null
  17.         bind = DataBindingUtil.setContentView(this, R.layout.activity_main) // binding layout
  18.         bind?.webview?.webViewClient = WebViewClient() // to open the link in my app not in phone's browser
  19.         bind?.webview?.settings?.javaScriptEnabled = true // to load that websites which will not work except JS
  20.         bind?.webview?.loadUrl("https://www.google.com") // link of the website which we want to show
  21.     }
  22. }
RAW Paste Data