android: webview inside dialog or popup

roy.d picture roy.d · Feb 7, 2012 · Viewed 61.4k times · Source

how to add web view inside dialog or popup window.

my web view hold URL WebView.loadurl() .when view added inside dialog it still moving to the browser.

I've been in android loading webview in dialog but is no example of how to do it? thanks

Answer

Dmytro Danylyk picture Dmytro Danylyk · Feb 7, 2012

Here is example:

AlertDialog.Builder alert = new AlertDialog.Builder(this); 
alert.setTitle("Title here");

WebView wv = new WebView(this);
wv.loadUrl("http:\\www.google.com");
wv.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);

        return true;
    }
});

alert.setView(wv);
alert.setNegativeButton("Close", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int id) {
        dialog.dismiss();
    }
});
alert.show();