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
Why Are These Permissions Being Refused
Android:Fill Spinner from Java Code Programmatically
How to Enable Usb Debugging in Android
File Res/Drawable/Abc_Ic_Ab_Back_Material.Xml from Drawable Resource Id #0X7F020016
Icon in Menu Not Showing in Android
Android Destroying Activities, Killing Processes
Using Disklrucache in Android 4.0 Does Not Provide for Opencache Method
Android Studio: Drawable Folder: How to Put Images for Multiple Dpi
Decoding Bitmaps in Android with the Right Size
How to Get Phone Number from an Incoming Call
How to Implement a Contentobserver for Call Logs
What Causes Android's Contentresolver.Query() to Return Null
How to Get Retrofit Success Response Status Codes
How to Create a .CSV on Android
An Android App Remembers Its Data After Uninstall and Reinstall
How to Create an Android Application in Android Studio That Uses the Google Maps API V2