簡體   English   中英

Android Webview 警報對話框按鈕 白色

[英]Android Webview Alert Dialog Button White colour

在此處輸入圖像描述

大家好。

我們有什么辦法可以更改 webview 中的警報對話框按鈕嗎? 目前,警告對話框按鈕是白色的,因為背景顏色也是白色,所以看不到。

嘗試更改 webview 用戶代理並嘗試覆蓋 onJsAlert,但沒有幫助。 我嘗試調試,但當顯示警報對話框時,它不會 go 進入 onJsAlert function。

    mContentWebView.setWebChromeClient(new WebChromeClient() {
            @Override
            public boolean onJsAlert(WebView view, String url, String message, final JsResult result) {
                AlertDialog dialog = new AlertDialog.Builder(view.getContext(), R.style.CustomAlertDialogStyle).
                        setTitle("YourAlertTitle").
                        setMessage(message).
                        setPositiveButton("OK", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                //do nothing
                            }
                        }).create();
                dialog.show();
                result.confirm();
                return true;
            }

試過手機web瀏覽器訪問網站,按鈕顏色為黑色。 就在 Android 應用程序中是白色的。

關於更改警報對話框按鈕顏色的任何建議?

提示為 onJsConfirm 已解決。

            @Override
            public boolean onJsConfirm(WebView view, String url, String message, JsResult result) {
                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityBrowserWithoutToolbar.this);
                alertDialogBuilder.setTitle(url);
                alertDialogBuilder.setMessage(message);
                alertDialogBuilder.setPositiveButton(
                        getString(R.string.ok_button),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                result.confirm();
                            }
                        });

                alertDialogBuilder.setNegativeButton(
                        getString(R.string.cancel_button),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                result.cancel();
                            }
                        });

                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.setOnShowListener(arg0 -> {
                    alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(getResources().getColor(R.color.accent_color));
                    alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(getResources().getColor(R.color.accent_color));
                });

                alertDialog.show();
                return true;
            }
        });

Alert Dialog使用的是activity主題,所以肯定按鈕顏色默認使用activity主題的colorAccent。 你應該檢查一下。

如果您沒有設置活動主題,請檢查您的應用主題的colorAccent。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM