Remove sign in button in google docs webview in android

前端 未结 4 1720
醉梦人生
醉梦人生 2020-12-11 17:12

I am showing PDF files by using google docs in WebView in android. How to remove or hide \"Sign In\" button? I have attached screenshot below. Thanks in advance

相关标签:
4条回答
  • 2020-12-11 17:31

    Try this

    I have tried to many answers but did not get good answer. Finally got the solution with adding few code in when loading the pdf into the webview .

     final WebView wv_webview= (WebView) view.findViewById(R.id.wv_webview);;
        wv_webview.getSettings().setJavaScriptEnabled(true);
        wv_webview.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
                wv_webview.loadUrl("javascript:(function() { " +
                        "document.querySelector('[role=\"toolbar\"]').remove();})()");
            }
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                wv_webview.loadUrl("javascript:(function() { " +
                        "document.querySelector('[role=\"toolbar\"]').remove();})()");
            }
        });
        String your_pdf_link="https://www.antennahouse.com/XSLsample/pdf/sample-link_1.pdf";
        wv_webview.loadUrl("https://docs.google.com/viewer?embedded=true&url=" + your_pdf_link);
    

    Note:- It will show only few milliseconds when pdf loads into webview

    Output:-

    0 讨论(0)
  • 2020-12-11 17:51

    I'd self-host your terms document, and I'd host it as .html file format rather than .pdf.

    If you do not have a domain in which to self-host the file, check other file hosting services and see if they offer a public option that won't request login. Potential services that may work for you include Mediafire, Cramitin, Hotfile, Rapidshare, etc. (this is not an ordered or comprehensive list, do your own search).

    0 讨论(0)
  • 2020-12-11 17:53

    Add the embedded=true parameter.

    webview = (WebView) findViewById(R.id.webView1);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.loadUrl("https://docs.google.com/viewer?embedded=true&url=http://www.runfreeordie.com/right_to_know.pdf");
    webview.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return false;
        }
    });
    

    Note: This answer was actually proposed by user3777879. Tested, and working, he should get the credit - Stuart

    0 讨论(0)
  • 2020-12-11 17:54
    webview.loadUrl("javascript:(function() { " +
                        "document.getElementsByClassName('drive-viewer-toolstrip')[0].style.visibility='hidden'; })()");
    
    0 讨论(0)
提交回复
热议问题