Webview控件在Android中不显示此弹出窗口

Webview控件在Android中不显示此弹出窗口,android,webview,popup,Android,Webview,Popup,在我的应用程序中,我在应用程序本身中使用webview控件来显示在线页面。但在它里面,我想显示一个警报或弹出窗口,他们显示的弹出窗口就像 我们所看到的 . 此时webview控件不显示此弹出窗口。请帮我弄清楚这件事 MainActivity.java import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.Dialo

在我的应用程序中,我在应用程序本身中使用webview控件来显示在线页面。但在它里面,我想显示一个警报或弹出窗口,他们显示的弹出窗口就像 我们所看到的 . 此时webview控件不显示此弹出窗口。请帮我弄清楚这件事

MainActivity.java

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends Activity {

    private WebView mWebview;
    private ProgressDialog progressBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        mWebview = (WebView) findViewById(R.id.webView1);
        WebSettings settings = mWebview.getSettings();
        settings.setAllowFileAccess(true);
        settings.setJavaScriptCanOpenWindowsAutomatically(true);
        settings.setJavaScriptEnabled(true);
        mWebview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
        progressBar = ProgressDialog
                .show(MainActivity.this, "", "Loading...", true);
        mWebview.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }

            public void onPageFinished(WebView view, String url) {
                if (progressBar.isShowing()) {
                    progressBar.dismiss();
                }
            }

            public void onReceivedError(WebView view, int errorCode,
                    String description, String failingUrl) {
                AlertDialog alert = new AlertDialog.Builder(MainActivity.this)
                        .create();
                alert.setTitle("No Network Connection");
                alert.setIcon(R.drawable.ic_launcher);
                alert.setCancelable(false);
                alert.setMessage("Please Try again");
                alert.setButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                alert.show();
            }
        });
        mWebview.loadUrl("http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/showModalDialog2.htm");
    }
}
activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<WebView
    android:id="@+id/webView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true" />

在HTML中,更准确地说,在fnOpen函数中,我看到:

window.showModalDialog("SMD_target.htm", "", sFeatures)
这不是一个好的选择,因为我们都喜欢IE,尤其是webview:-

下面是一篇很好的帖子,为什么你应该避免它:

如果需要弹出窗口,请将其包装在AlertDialog中,本文将对此进行讨论:

您可以从JS代码中调用Java代码,请阅读我的回答:


我希望这能对你有所帮助。

好的,请告诉我你到底有什么问题。此时webview控件不显示此弹出窗口。所以,我的结论是:按下按钮后,必须出现一个弹出窗口。