What are Xamarin and Xamarin Forms?

Prerequisites

The steps given below are required to be followed in order to create Web View Android in Xamarin Android, using Microsoft Visual Studio 2017.

Step 1

Step 2

In this step, proceed as shown below.

Step 3

Afterwards, go to

Step 4

In this step, go to cs page, insert the code given below in MainActivity.cs aand save it.

Xamarin

Xamarin
  1. using System;
  2. using Android.App;
  3. using Android.Content;
  4. using Android.Runtime;
  5. using Android.Views;
  6. using Android.Webkit;
  7. using Android.Widget;
  8. using Android.OS;
  9. using WebView_Android.Views;
  10. using WebView_Android.Models;
  11. using Android.Graphics;
  12. namespace WebView_Android
  13. {
  14. [Activity(Label = "WebView_Android", MainLauncher = true)]
  15. public class MainActivity : Activity
  16. {
  17. protected override void OnCreate(Bundle bundle)
  18. {
  19. base.OnCreate(bundle);
  20. SetContentView(Resource.Layout.Main);
  21. var webView = FindViewById<WebView>(Resource.Id.webView);
  22. webView.Settings.JavaScriptEnabled = true;
  23. webView.SetWebViewClient(new HybridWebViewClient());
  24. // Render the view from the type generated from RazorView.cshtml
  25. webView.LoadUrl("http://www.google.co.in");
  26. }
  27. public class HybridWebViewClient : WebViewClient
  28. {
  29. public override bool ShouldOverrideUrlLoading(WebView view, string url)
  30. {
  31. view.LoadUrl(url);
  32. return true;
  33. }
  34. public override void OnPageStarted(WebView view, string url, Android.Graphics.Bitmap favicon)
  35. {
  36. base.OnPageStarted(view, url, favicon);
  37. }
  38. public override void OnPageFinished(WebView view, string url)
  39. {
  40. base.OnPageFinished(view, url);
  41. }
  42. public override void OnReceivedError(WebView view, [GeneratedEnum] ClientError errorCode, string description, string failingUrl)
  43. {
  44. base.OnReceivedError(view, errorCode, description, failingUrl);
  45. }
  46. }
  47. }
  48. }

Step 5

Step 6

In this step, select Build & depoly option, followed by clicking to start your Application.

Now, go to Run option, choose Debug and the list of an Android Simulator. You can choose any API Level Simulator and run it.

Xamarin

Step 7

Output

Conclusion

Thus, we learned how to create Web View Application in an Android, using Xamarin on Visual Studio 2017.