屏幕截图:The page at file://
无论如何都要修改警告框标题?任何帮助将不胜感激。 :)
答案 0 :(得分:12)
确实,你可以使用以下代码包围它:
final Context myApp=this;
webView.setWebChromeClient(new WebChromeClient(){
@Override
public boolean onJsAlert(WebView view, String url, String message, final android.webkit.JsResult result)
{
new AlertDialog.Builder(myApp)
.setTitle("Simmon says...")
.setMessage(message)
.setPositiveButton(android.R.string.ok,
new AlertDialog.OnClickListener()
{
public void onClick(DialogInterface dialog, int wicht)
{
result.confirm();
}
}).setCancelable(false)
.create()
.show();
return true;
};
});
代码来源here
GL
答案 1 :(得分:1)
@Pointy表示,由于浏览器的安全措施,这是不可能的。
答案 2 :(得分:1)
有 3 种类型的js警报:
我已经添加了onJsConfirm的示例代码,
webViewLayout.setWebChromeClient(new WebChromeClient(){
@Override
public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
AlertDialog dialog =new AlertDialog.Builder(view.getContext()).
setTitle("Confirm").
setIcon(ContextCompat.getDrawable(view.getContext(),R.drawable.image)).
setMessage(message).
setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
result.cancel();
}
}).
setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
FlashMessage("JS");
result.confirm();
}
})
.create();
dialog.show();
return true;
}
});
答案 3 :(得分:0)
是的可能,我做到了
webview.setWebChromeClient(new WebChromeClient() {
public boolean onJsAlert(WebView view, String url, String message, final android.webkit.JsResult result)
{
new AlertDialog.Builder(activity)
.setTitle("Calendário App...")
.setMessage(message)
.setPositiveButton(android.R.string.ok,
new AlertDialog.OnClickListener()
{
public void onClick(DialogInterface dialog, int wicht)
{
result.confirm();
}
}).setCancelable(false)
.create()
.show();
return true;
};
});