在我的应用中,我在应用中使用webview控件来显示在线页面。但在其中,我想显示一个警告或弹出窗口,他们正在显示弹出窗口 我们所看到的 Sample Popup。现在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" />
答案 0 :(得分:0)
在你的HTML中,更准确地说是在fnOpen() - 函数中,我看到了:
window.showModalDialog("SMD_target.htm", "", sFeatures)
这不是一个好选择,因为我们所有人都喜欢&#34; IE,特别是webview的确:-)
这是一个很好的帖子,你应该避免它: http://tjvantoll.com/2012/05/02/showmodaldialog-what-it-is-and-why-you-should-never-use-it/
如果你需要弹出窗口,请将它包装在AlertDialog中,在本文中讨论:android: webview inside dialog or popup
您可以从JS代码中调用Java代码,请在此处阅读我的答案:How to call javascript function from java when webview page is different
我希望这会对你有所帮助。