Hello,
Welcome to our Microsoft Q&A platform!
I test it in my Android 11 environment, and set the target-framework to the android 11.
I test WebView source is <WebView Source="https://www.google.com.hk/" WidthRequest="200" HeightRequest="500"></WebView>
. And here is my webview custom renderer.
[assembly: ExportRenderer(typeof(WebView), typeof(MyWebViewRenderer))]
namespace WebViewDemo.Droid
{
class MyWebViewRenderer : WebViewRenderer
{
public MyWebViewRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
{
base.OnElementChanged(e);
Control.Settings.JavaScriptEnabled = true;
Control.SetWebViewClient(new MyWebViewClient());
}
}
internal class MyWebViewClient : Android.Webkit.WebViewClient
{
public override Android.Webkit.WebResourceResponse ShouldInterceptRequest(Android.Webkit.WebView view, Android.Webkit.IWebResourceRequest request)
{
return base.ShouldInterceptRequest(view, request);
}
public override bool ShouldOverrideUrlLoading(Android.Webkit.WebView view, Android.Webkit.IWebResourceRequest request)
{
return base.ShouldOverrideUrlLoading(view, request);
}
}
I add the breakpoint in the ShouldOverrideUrlLoading
method. when I click the links, ShouldOverrideUrlLoading
will be executed as excepted like following screenshot.
My Xamarin forms version is 5.0.0.2012, VS version is 16.10.0. You can create a new project to make a test.
Best Regards,
Leon Lu
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.