WebView on AlertDialog

0

Good morning everyone: I am trying to place a WebView in an AlertDialog which I want to show a shared Google Drive Document, of which I know its public URL.

When I indicate a URL (eg google.com), the WebView is displayed correctly, but when I indicate the URL of the shared file, the height of the WebView is very small.

I have tried many codes but they all have the same problem, here is the code.

private void CargarURL (String sURL) {

        final View view = getActivity().getLayoutInflater().inflate(R.layout.alertnotic, null);

        AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
        builder.setCancelable(false);

        final WebView webview  = (WebView) view.findViewById(R.id.wNotic);
        String url = sURL;
        webview.getSettings().setAllowFileAccess(true);
        webview.getSettings().setBuiltInZoomControls(true);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.setWebChromeClient(new WebChromeClient());
        webview.loadUrl(url);

        webview.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
        builder.setNegativeButton("Cancelar",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });

        final AlertDialog dialog = builder.create();
        dialog.setView(view);
        dialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialogInterface) {
                //dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(ContextCompat.getColor(getContext(),R.color.colorAccentDark));

            }
        });
        // display dialog
        dialog.show();
    }

Some screenshots: with file url (the black part is the WebView, apparently if you upload the file online but it is not displayed correctly.

with google url

    
asked by Jorny 06.06.2017 в 17:18
source

0 answers