WebView不会在对话框中显示

时间:2012-10-23 20:39:51

标签: android webview dialog

我在对话框中遇到WebView问题。我尝试了很多不同的技巧但没有任何效果。所以,我的问题是我无法在自定义对话框中加载WebView。它会打开对话框并且不会出现任何错误,但对话框不会“填充”Web视图。它只显示对话框的标题。

AlertDialog.Builder会在对话框中打开webview,但在单击输入字段时不会打开键盘。如果我打开键盘,它会出现在对话框后面。 (这似乎是已知的错误...)

Dialog alert = new Dialog(Activity.this );

        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.web, null);

        alert.setContentView(view);
        alert.setTitle("WebView");
        alert.setCancelable(true);

        WebView w = (WebView) view.findViewById(R.id.web);
        w.setWebViewClient(new WebViewClient() );
        w.getSettings().setUserAgentString("useri");
        w.loadUrl("http://google.com");

        alert.show();

和R.layout.web文件:

<?xml version="1.0" encoding="utf-8"?>

<WebView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/web"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:minHeight="9999dp"
    android:minWidth="9999dp" />

如何在对话框中打开网页视图?

2 个答案:

答案 0 :(得分:0)

你应该将minHeight和minWidth设置为如此荒谬的值。删除这些,它应该工作。也可能最好将WebView设置为Fill parent,以便填充整个Dialog(如果这就是你想要的)。

答案 1 :(得分:0)

尝试以编程方式将WebView添加到Dialog而不是使用XML。