[英]Xamarin Native Webview Android
I have a Webview in my Xamarin Android App but when i want to use Webview.navigate this does not exsist in the event list. 我的Xamarin Android应用程序中有一个Webview,但是当我想使用Webview.navigate时,它不存在于事件列表中。 I want to execute code when the user navigate.
我想在用户导航时执行代码。 But like I said i have no navigate event.
但是就像我说的,我没有导航事件。
Please help me. 请帮我。
I was facing something similar and managed to solve it by implementing a custom WebViewClient and by setting the WebView 's WebViewClient using the method : SetWebViewClient . 我面临着类似的问题,并设法通过实现自定义WebViewClient并通过使用SetWebViewClient方法设置WebView的WebViewClient来解决该问题 。 Take this code for example :
以下面的代码为例:
public class CustomWebViewClient : WebViewClient
{
public event EventHandler<bool> OnPageLoaded;
public override bool ShouldOverrideUrlLoading(WebView view, IWebResourceRequest request)
{
view.LoadUrl(request.Url.ToString());
return true;
}
public override void OnPageStarted(WebView view, string url, global::Android.Graphics.Bitmap favicon)
{
base.OnPageStarted(view, url, favicon);
}
public override void OnPageFinished(WebView view, string url)
{
OnPageLoaded?.Invoke(this, true);
}
public override void OnReceivedError(WebView view, IWebResourceRequest request, WebResourceError error)
{
OnPageLoaded?.Invoke(this, false);
}
}
And on your activity : 在您的活动上:
var wbMain = FindViewById<WebView>(Resource.Id.wbMain);
var customWebViewClient = new CustomWebViewClient();
customWebViewClient.OnPageLoaded += CustomWebViewClient_OnPageLoaded;
wbMain.SetWebViewClient(customWebViewClient);
wbMain.LoadUrl("http://the.page.to.load");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.