Converting Website into Android App using WebView

Hi, Another tutorial here about Converting Website into Android App using WebView, a webview is a view which displays webpages converting web in to application. With webview you can load remote url using loadUrl() method or even load dynamic html using loadData() method. To work with webview we need to add INTERNET permission in our application.

  • To load dynamic html we use loadData method which require String name, String mimeType, String encoding.
  • We need to enable canGoBack() and canGoForward method for use to be able to go back and forward.
  • We also need to set webViewClient in our webView which monitor the activity of webview.
  • Lets now get start developing our application.
  • Creating new Android Studio Project

  • Open your android studio click File => New Project and give it a name you can call it WebView Tutorial .
  • Click next and select Empty activity and then finish.
  • Adding webview in our activity_main

  • Open your activity_main and add two button.
  • One button will loadwebsite when clicked.
  • Converting Website into Android App using WebView

  • The other button will load dynamic html when clicked
  • Converting Website to Android App  using WebView

  • Also add webview which will load our website when the buttons are clicked.
  • copy and paste the code below in your activity_main.
  • Configuring Webview

  • To configure webview open your MainActivity class.
  • In this class we are going to setWebViewClient.
  • set canGoBack to enable user to get to the previous page when back button is pressed.
  • Create a custom HTML to be loaded when load html button is clicked.
  • Copy and paste the code below to your MainActivity class.
  • Adding INTERNET permission

  • Finally we need to add internet permission.
  • Open Mainifest file and add the following permission.
  • Now run your application and you will see output working as shown below.
  • Converting Website into Android App using WebView

  • That all if you a question or need help please comment below.