Remove sign in button in google docs webview in android

前端 未结 4 1721
醉梦人生
醉梦人生 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:-

提交回复
热议问题