2

I am trying to make an Android dialog that shows a webview:

final Dialog dialog = new Dialog(mActivity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.layout);
WebView webView = (WebView)dialog.findViewById(R.id.webview);
webView.setWebChromeClient(new WebChromeClient());

String customHtml = "<html><body>WebViewTest</body></html>";
webView.loadData(customHtml, "text/html", "UTF-8");
dialog.show();

But nothing is happening. It appears the webview has no size

I have been asked for the xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:minHeight="300dp"
    android:padding="10sp"
    android:background="#0ff"
    android:orientation="vertical">
    <WebView
        android:background="#f0f"
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</LinearLayout>
JackFinch
  • 48
  • 6

2 Answers2

1

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();
Community
  • 1
  • 1
Quintin Balsdon
  • 5,484
  • 10
  • 54
  • 95
  • 1
    @JackFinch ,If this answer was helpful for you then tick the green mark rather that saying simply "Thank you" , this way it also helps future users too. – Lucifer Aug 12 '15 at 10:20
0
final Dialog dialog = new Dialog(mActivity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.layout);
WebView webView = (WebView)dialog.findViewById(R.id.webview);
webView.setWebChromeClient(new WebChromeClient());
String customHtml = "<html><body>WebViewTest</body></html>";
webView.loadData(customHtml, "text/html; charset=UTF-8", null);
dialog.show();
sasikumar
  • 12,540
  • 3
  • 28
  • 48