Modify alert() title (Javascript in Android Webview)

前端 未结 3 1181
北恋
北恋 2021-02-15 18:45

Screenshot: The page at file://

Is there anyway to modify the alert box title? Any help will be greatly appreciated. :)

3条回答
  •  说谎
    说谎 (楼主)
    2021-02-15 19:01

    Indeed you can envelop it using the following code:

        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;
        };
        });
    

    Code source here

    gl

提交回复
热议问题