甜蜜警报中的动作按钮的彩色背景(Android)

时间:2016-06-25 18:17:53

标签: android android-layout sweetalert

我已经编写了一些代码,用于显示使用甜蜜警报库的对话框。它是一个非常受欢迎的库,包含几个非常有用的功能,这些功能对于设计目的和开发目的也非常有用。因此,请帮助更改对话框底部的“操作”按钮的背景颜色。

我附加了屏幕截图和代码。请帮我解决这个问题。

我只想更改Action Button的背景颜色。

 MaterialDialog.Builder builder = new MaterialDialog.Builder(SignInActivity.this)
                                     .title("Sign Up")
                                     .titleColor(Color.BLACK)
                                     .customView(R.layout.custom_dialog_sign_up, true)
                                     .positiveText("Submit")
                                     .negativeText("Cancel")
                                     .positiveColorRes(R.color.black_color)
                                     .negativeColorRes(R.color.gray_btn_bg_color)
                                     .canceledOnTouchOutside(false)
                                     .autoDismiss(false);

    final MaterialDialog materialDialog = builder.build();

    materialDialog.show(); 

2 个答案:

答案 0 :(得分:2)

回答你的问题已经很晚了,但是,最近我面对这个问题,并开始在谷歌上挖掘但没有发现任何东西,所以我开始自己的,发现这个完美的解决方案代码和屏幕截图附加。

enter image description here

SweetAlertDialog sweetAlertDialogView;
sweetAlertDialogView = new SweetAlertDialog(ctx,SweetAlertDialog.ERROR_TYPE);
 sweetAlertDialogView.setTitleText(ctx.getResources().getString(R.string.error_msg_oops_title))
                    .setContentText("Request failed :" + errMsg + " \n" + ctx.getResources().getString(R.string.error_msg_check_net_connection));
            sweetAlertDialogView.show();
            Button viewGroup = (Button) sweetAlertDialogView.findViewById(cn.pedant.SweetAlert.R.id.confirm_button);
            if (viewGroup != null) {
                Log.e(TAG, "showErrorMsg: Button view Found yep");
                viewGroup.setBackgroundColor(viewGroup.getResources().getColor(R.color.colorSkyBlueButtonLoader));
            } else {
                Log.e(TAG, "showErrorMsg: Button view Null :( ");
            }

从逻辑上方我将按钮颜色更新为深蓝色天蓝色,对于任何其他帮助,您可以在评论中询问我。我会尽力解决它。

答案 1 :(得分:1)

更容易实现此目的的方法是在color.xml中覆盖以下颜色值:

<color name="blue_btn_bg_color">#1976D2</color>
<color name="blue_btn_bg_pressed_color">#1565C0</color>
相关问题