1. 程式人生 > >Xamarin.Android 嵌入web端介面

Xamarin.Android 嵌入web端介面

  在程式中嵌入Web端介面。

首先在前臺介面上建立一個webview

<android.webkit.WebView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/webView1" />

然後後臺程式碼提供呼叫的介面

using Android.App;
using Android.Widget;
using Android.OS;
using Android.Webkit;
using Android.Net.Http; namespace App5 { [Activity(Label = "App5", MainLauncher = true)] public class MainActivity : Activity { protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main); } /// <summary> /// 跳轉回來重新整理資料 /// </summary> protected override void OnResume() { base.OnResume(); GetListData(); } /// <summary> /// 獲取資料
/// </summary> void GetListData() { WebView _webview = FindViewById<WebView>(Resource.Id.webView1); _webview.LoadUrl("https://www.baidu.com/"); _webview.Settings.JavaScriptEnabled = true; _webview.Settings.SetSupportZoom(true); _webview.Settings.BuiltInZoomControls = true; _webview.Settings.UseWideViewPort = true; _webview.Settings.DisplayZoomControls = false; _webview.SetWebViewClient(new ExtWebViewClient()); } public class ExtWebViewClient : WebViewClient { public override void OnReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { handler.Proceed(); //base.OnReceivedSslError(view, handler, error); } } } }