Hello,
Welcome to our Microsoft Q&A platform!
how to make the app recognize that I'm clicking a link. Could someone please tell me if there is a way to check when I touch the webview if I am clicking a link please?
Webview have a ShouldOverrideUrlLoading
method of WebViewClient
In the Android, if user click the hyper link, this method ShouldOverrideUrlLoading
will be execute. You can use custom renderer for your webview like following code. You can get all of links by request.Url;
[assembly: ExportRenderer(typeof(WebView), typeof(MyWebviewRenderer))]
namespace ImageLongClickDemo.Droid
{
class MyWebviewRenderer : WebViewRenderer
{
public MyWebviewRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
Control.SetWebViewClient(new MyWebviewClient());
}
}
}
internal class MyWebviewClient : Android.Webkit.WebViewClient
{
public override bool ShouldOverrideUrlLoading(Android.Webkit.WebView view, Android.Webkit.IWebResourceRequest request)
{
var MyUrl=request.Url;
Toast.MakeText(Android.App.Application.Context,MyUrl.ToString(),ToastLength.Short).Show();
return base.ShouldOverrideUrlLoading(view, request);
}
}
}
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
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.