What are Xamarin and Xamarin Forms?
- Xamarin is a cross-platform to develop Multi-Platform Applications.
- Xamarin is a shared code(C#) but separately designs UIs Android(Java), Windows(C#) and an iOS.
- Xamarin forums is UIs & Shared code (C#) are same. To develop multi-platforms Applications, run all the projects (Android, Windows and an IOS) at the same time.
Prerequisites
- Visual Studio 2017 Enterprise.
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
- Go to Visual Studio 2017.
- Click File -> New -> Project.
Step 2
In this step, proceed as shown below.
- Click C# -> Android -> Web View app (Android).
- Enter the Application Name.
- Web View = Create an Android Web View Application, whicht uses the Razor templating engine.
Step 3
Afterwards, go to
- Open Solution Explorer Window.
- Now, click -> cs.
Step 4
In this step, go to cs page
, insert the code given below in MainActivity.cs aand save it.
- using System;
- using Android.App;
- using Android.Content;
- using Android.Runtime;
- using Android.Views;
- using Android.Webkit;
- using Android.Widget;
- using Android.OS;
- using WebView_Android.Views;
- using WebView_Android.Models;
- using Android.Graphics;
-
- namespace WebView_Android
- {
- [Activity(Label = "WebView_Android", MainLauncher = true)]
- public class MainActivity : Activity
- {
- protected override void OnCreate(Bundle bundle)
- {
- base.OnCreate(bundle);
-
- SetContentView(Resource.Layout.Main);
- var webView = FindViewById<WebView>(Resource.Id.webView);
- webView.Settings.JavaScriptEnabled = true;
- webView.SetWebViewClient(new HybridWebViewClient());
-
- webView.LoadUrl("http://www.google.co.in");
-
- }
- public class HybridWebViewClient : WebViewClient
- {
- public override bool ShouldOverrideUrlLoading(WebView view, string url)
- {
-
- view.LoadUrl(url);
- return true;
- }
- public override void OnPageStarted(WebView view, string url, Android.Graphics.Bitmap favicon)
- {
- base.OnPageStarted(view, url, favicon);
- }
- public override void OnPageFinished(WebView view, string url)
- {
- base.OnPageFinished(view, url);
- }
- public override void OnReceivedError(WebView view, [GeneratedEnum] ClientError errorCode, string description, string failingUrl)
- {
- base.OnReceivedError(view, errorCode, description, failingUrl);
- }
-
-
-
-
- }
- }
-
- }
Step 5
- Click Build menu and go to Configuration Manager.
- Configure your Android Application to depoly & build Setting. Click Close.
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.
Step 7
Output
- After a few seconds, the app will start running on your Android Simulator. You will see your app is working & is created successfully.
- Your Web View Android Application is created succesfully.
Conclusion
Thus, we learned how to create Web View Application in an Android, using Xamarin on Visual Studio 2017.