Xamarin WebView使用(一)

今天学习了一下使用Xamarin中的webview控件来打开网页


首先,先创建了一个layout,在里面放置一个webview控件



    


然后新建一个Activity

public class ShopActivity : Activity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Shop);
            // Create your application here
            WebView _webview = FindViewById(Resource.Id.webView1);

            _webview.LoadUrl("https://shop444140054.taobao.com/?spm=a230r.7195193.1997079397.2.JxOGq1");
            _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);
        }
    }

起初我在 ExtWebViewClient中重写了ShouldOverrideUrlLoading

public override bool ShouldOverrideUrlLoading(WebView view,string url)
{ 
	view.LoadUrl(url);
	return true;
}

但是此方法在遇到非http、https开头的url时,会出现位于xxxx://XXXXX.XXXXXXX.XXXX的网页无法加载,因为net::ERR_UNKNOWN_URL_SCHEME




你可能感兴趣的:(Xamarin.Android)