How to add White color to web view Background

lak1104lak1104 Member ✭✭

I have a web view to show the pdf. When it displaying the pdf it's not taking full area it's not the issues with me, but the background color of it shows a kind of dark color background I need to remove that dark color to white how to do this in xamarin forms

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai

    @lak1104
    Have you tried to set BackgroundColor of WebView to white or set BackgroundColor of WebView's parent layout to white?

    <StackLayout BackgroundColor="White">
         <WebView Source="https://www.google.com" BackgroundColor="White" ... />
    </StackLayout>
    
  • lak1104lak1104 Member ✭✭

    @yelinzh Yes, of course, I tried out that also. It does not work

  • JarvanJarvan Member, Xamarin Team Xamurai

    Try to create a webView _renderer and set Control.Settings.AllowUniversalAccessFromFileURLs to true.

    namespace DisplayPDF.Droid
    {
        public class CustomWebViewRenderer : WebViewRenderer
        {
            protected override void OnElementChanged (ElementChangedEventArgs<WebView> e)
            {
                base.OnElementChanged (e);
    
                if (e.NewElement != null) {
                    var customWebView = Element as CustomWebView;
                    Control.Settings.AllowUniversalAccessFromFileURLs = true;
                    Control.LoadUrl (string.Format ("file:///android_asset/pdfjs/web/viewer.html?file={0}", string.Format ("file:///android_asset/Content/{0}", WebUtility.UrlEncode (customWebView.Uri))));
                }
            }
        }
    }
    

    Refer to: https://stackoverflow.com/a/56390605/11083277

  • lak1104lak1104 Member ✭✭

    @yelinzh I did all these steps but the result is the same

  • JarvanJarvan Member, Xamarin Team Xamurai

    Would you mind sharing a basic demo? It'll help to reproduce the issue and fina a solution.

Sign In or Register to comment.