Xamarin Forms – Webview page’s click and horizontal scroll is not working

Issue

I have a webview in Xamarin Forms app for render html content and privacy policy. I’am facing two issues, that are follows.

  • Content page or page popups are not respond to the click action.
  • Images are displayed in the page are in bigger size and I’am not able to scroll those image horizontally.

Note: In iOS everything is working fine, no issues.

Pleas see my droid render implementation.

public override bool DispatchTouchEvent(MotionEvent e)
{
    RequestDisallowInterceptTouchEvent(true);
    return base.OnTouchEvent(e);
}

protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
{
    base.OnElementChanged(e);

    if (null  e.OldElement)
    {
        var webView  Element as CustomWebView;
        Control.SetBackgroundColor(Android.Graphics.Color.Transparent);
        Control.Settings.AllowUniversalAccessFromFileURLs  true;
        Control.Settings.BuiltInZoomControls  true;
        Control.Settings.DisplayZoomControls  true;
        Control.Settings.JavaScriptEnabled  true;
        Control.Settings.DomStorageEnabled  true;
        Control.Settings.EnableSmoothTransition();
        Control.Settings.SetSupportMultipleWindows(true);

        Control.SetWebViewClient(new ExtendedWebViewClient(webView));
        Control.SetWebChromeClient(new MyWebChromeClient());

        Control.LoadUrl(control.Uri);
    }
}

I have tried different options but no luck. Any help will be really appreciated.

Solution

Please disable DispatchTouchEvent method.Just use webView.Settings.UseWideViewPorttrue; in your WebViewRenderer. You can use following code in your WebViewRenderer

 var webView  (global::Android.Webkit.WebView)Control;
 webView.Settings.UseWideViewPorttrue;

If I have long button. if I add this attribute, here is running GIF.

enter image description here

Answered By – Leon Lu – MSFT

Leave a Comment