-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode
63 lines (53 loc) · 2.76 KB
/
code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Hello, copy this code to visual studio. Default project name : WEBVIEW
// Follow these steps as well
// 1- At first, go to MainActivity.cs and paste this :
//*********************************************************************************************************************
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Webkit;
namespace WEBVIEW
{
[Activity(Label = "Mohamad Nazzal Web View", MainLauncher = true, Theme = "@android:style/Theme.NoTitleBar")]
public class MainActivity : Activity
{
private WebView web; //WebView here is a type
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView (Resource.Layout.Main);
web = FindViewById<WebView>(Resource.Id.webview);
web.Settings.JavaScriptEnabled = true;
web.LoadUrl("http://mohamadnazzal.me"); // Here you can add your website
web.SetWebViewClient(new HelloWebViewClient());
}
public class HelloWebViewClient : WebViewClient
{
public override bool ShouldOverrideUrlLoading(WebView view, string url)
{
view.LoadUrl(url);
return true;
}
}
}
}
//*********************************************************************************************************************
// 2- Now go to AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="me.mohamadnazzal" android:versionCode="1" android:versionName="1.0" android:installLocation="internalOnly">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET"/> // This line helping the app to connect to the internet
<application android:label="Mohamad Nazzal Official" android:icon="@drawable/Icon"></application>
</manifest>
//*********************************************************************************************************************
//3- Go to Main.axml
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
//*********************************************************************************************************************
// Don't forget to add an icon as you like in Drawable as Icon.png
// Visit http://mohamadnazzal.me , feel free to ask me any question.
// SOURCE : https://developer.xamarin.com/guides/android/user_interface/web_view/
// Preview this code in a real app : https://play.google.com/store/apps/details?id=me.mohamadnazzal&hl=en