直接复制吧!0.0
webView.setWebChromeClient(new NoAdWebChromeClient() {
//本方法是用来显示只有确定按钮的弹框
@Override
public boolean onJsAlert(WebView view, String url, String message,
final JsResult result) {
final AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext());
builder.setTitle("提示")
.setMessage(message)
.setPositiveButton("确定", null);
// 不需要绑定按键事件
// 屏蔽keycode等于84之类的按键
builder.setOnKeyListener(new DialogInterface.OnKeyListener() {
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
Log.v("onJsAlert", "keyCode==" + keyCode + "event=" + event);
return true;
}
});
// 禁止响应按back键的事件
builder.setCancelable(false);
AlertDialog dialog = builder.create();
dialog.show();
result.confirm();// 因为没有绑定事件,需要强行confirm,否则页面会变黑显示不了内容。
return true;
}
//本方法是用来显示有确定和取消两个按钮的弹框
@Override
public boolean onJsConfirm(WebView view, String urls, final String message,
final JsResult result) {
new AlertDialog.Builder(WebInterfaceActivity.this).setTitle("提示").setMessage(message)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
result.confirm();
}
}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
result.cancel();
}
}).show();
return true;
}
//这个方法用来判断网页的加载进度
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
if (newProgress == 100) {
progressBar2.setVisibility(View.GONE);// 加载完网页进度条消失
} else {
progressBar2.setVisibility(View.VISIBLE);// 开始加载网页时显示进度条
progressBar2.setProgress(newProgress);// 设置进度值
}
}
});