Can someone give one exact example of webview implementation in android

AndroidMobile DevelopmentProgramming

Before getting into webview implementation we should know what is webview. Webview is a extended of a view and it is used to show HTML content or web pages.

Methods are available in webview.

  • clearHistory() − it is used to clear webview history

  • destroy() − It is used to destroy internal state of webview.

  • getUrl() −it is used to return current webview url.

  • getTitle() − It is used to return current webview tittle.

  • canGoBack() − It indicates about current webview has back history items.

Using webview, it opens webview content in default android browsers. If you want to open inside of application. ShouldOverrideUrlLoading as shown below.

private class MyWebViewClient extends WebViewClient {
   public boolean shouldOverrideUrlLoading(WebView webView, String url) {
      return false;

This example demonstrate about how to implement webview in android.

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.

Step 2 − Add the following code to res/layout/activity_main.xml.

<?xml version = "1.0" encoding = "utf-8"?>
   xmlns:android = "" xmlns:tools = ""
   android:layout_width = "match_parent"
   android:layout_height = "match_parent">
      android:layout_width = "match_parent"
      android:layout_height = "match_parent"
      android:id = "@+id/webView" />

Step 3 − Add the following code to src/

package com.example.andy.myapplication;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import timber.log.Timber;
public class MainActivity extends AppCompatActivity {
   private WebView simpleWebView;
   private ProgressBar loadProgress;
   protected void onCreate(Bundle savedInstanceState) {
      simpleWebView.setWebViewClient(new WebViewClient());
   public void onBackPressed() {
      if (simpleWebView.canGoBack()) {
      } else {

In the above code you can give your own website in loadUrl();

Step 4 − Add the following code to AndroidManifest.xml.

<?xml version = "1.0" encoding = "utf-8"?>
<manifest xmlns:android = ""
   package = "com.example.andy.myapplication">
<uses-permission android:name = "android.permission.INTERNET"/>
      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">
            <action android:name = "android.intent.action.MAIN" />
            <category android:name = "android.intent.category.LAUNCHER" />

In the above code we have given internet permission because we are calling website from internet source.

Step 5 − Add the following code to res/values/string.xml.

   <string name = "app_name">My Application</string>
   <string name = "erroopsproblem">Something error</string>

Let's try to run your application. I assume you have connected your actual Android Mobile device with your computer. To run the app from android studio, open one of your project's activity files and click Run Play Icon  icon from the toolbar. Select your mobile device as an option and then check your mobile device which will display your default screen.

Tutorials Point Html

Now when you click on something. For example click on HTML icon as shown above. it will give the result as shown below

HTML Tutorial

Click here to download the project code

Updated on 30-Jul-2019 22:30:23