Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android: webview inside dialog or popup

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

like image 734
roy.d Avatar asked Feb 07 '12 08:02

roy.d


2 Answers

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(); 
like image 51
Dmytro Danylyk Avatar answered Oct 02 '22 21:10

Dmytro Danylyk


You need to override setWebViewClient()..

mWebView = (WebView) view.findViewById(R.id.wv1); mWebView.setWebViewClient(new WebViewClient() {     @Override     public boolean shouldOverrideUrlLoading(WebView view, String url) {         view.loadUrl(url);         return false;     } }); mWebView.loadUrl(mUrl); 
like image 30
Rajdeep Dua Avatar answered Oct 02 '22 20:10

Rajdeep Dua