Android: Webview Inside Dialog or Popup

android: webview inside dialog or popup

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();

How to put android WebView in AlertDialog?

Have you added the INTERNET Permission to the Manifest?
<uses-permission android:name="android.permission.INTERNET"/>

You got to create an xml layout fisrt, and put the webview in the layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<!--Configure the webview as you want-->
<WebView
android:id="+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</WebView>

</LinearLayout>

create a view object instead a webview

View view = LayoutInflater.from(context).inflate(R.layout.layout_with_webview , null)

Now to crete a webview object use WebView webView = view.findViewById(R.id.webview)
Pass that view to alert.setView(view)

And the most important alertDialogBuilder.show()

android loading webview in dialog

You can just apply dialog theme to regular activity which contains a WebView.

webview inside an alertBuilder, keyboard doesnt pop up

You can define fake keyboard like this:

 AlertDialog.Builder alert = new AlertDialog.Builder(this); 
WebView wv = new WebView(this);
LinearLayout wrapper = new LinearLayout(this);
EditText keyboardHack = new EditText(this);
keyboardHack.setVisibility(View.GONE);
wv.getSettings().setJavaScriptEnabled(true);
wv.loadUrl(loadUrl);
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);

return true;
}
});

wrapper.setOrientation(LinearLayout.VERTICAL);
wrapper.addView(wv, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
wrapper.addView(keyboardHack, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
alert.setView(wrapper);

WebView not loading URL in Dialog

I would suggest looking here: android: webview inside dialog or popup

Rather use an AlertDialog, it will better suite your needs:

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();

Android - Webview in pop up dialog?

Could you please supply more code (maybe the entire method/class) so we can see the context in which this is placed. There is a good chance that the previous code is causing this part to crash.



Related Topics



Leave a reply



Submit