截图:文件://
有没有办法修改警告框标题?非常感谢您的帮助。 :)
确实可以使用以下代码封装它:
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;
};
});
代码来源在这里
gl
有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;
}
});
是的,这是可能的,我曾经做过
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;
};
});