Xamarin中WebView問題記錄

1.使用WebView進行瀏覽器嵌套時, WebView會打開手機中默認瀏覽器,而不是嵌套在WebView當中。web

解決方法:重寫WebViewClientShouldOverrideUrlLoading方法。瀏覽器

public class WebViewCustClient : WebViewClient
{
    public override bool ShouldOverrideUrlLoading(WebView view, string url)
    {
        view.LoadUrl(url);
        return base.ShouldOverrideUrlLoading(view, url);
    }
    public override void OnPageStarted(WebView view, string url, Bitmap favicon)
    {
        base.OnPageStarted(view, url, favicon);
    }
}

2.打開www.baidu.com等頁面沒問題,可是打開一些頁面加載不出顯示爲空白時。ide

解決方法:對WebSetting的設置所有設置。ui

WebView webview = FindViewById<WebView>(Resource.Id.webView1);
//設置可自由縮放網頁  
WebSettings set = webview.Settings;

set.JavaScriptCanOpenWindowsAutomatically = true;   
set.JavaScriptEnabled = true;                       
set.SetSupportZoom(true);
set.BuiltInZoomControls = true;                     
set.UseWideViewPort = true;                         
set.CacheMode = CacheModes.Default;                 
set.SetLayoutAlgorithm(LayoutAlgorithm.SingleColumn);
set.LoadWithOverviewMode = true;                    
set.SetAppCacheEnabled(true);
set.DomStorageEnabled = true;                       
webview.SetWebViewClient(new WebViewCustClient());
webview.LoadUrl("");
相關文章
相關標籤/搜索