更改 Sweet alert 中的按钮样式

Change button style in Sweet alert

我正在为 android 使用 SweetAlert 对话框。

https://github.com/pedant/sweet-alert-dialog

在成功对话框中,我想删除 OK Button 并更改其样式。请说明如何删除确定按钮。

我在单击按钮时调用方法

new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE)
    .setTitleText("Good job!")
    .setContentText("You clicked the button!")
    .show();

试试这个

dialog.findViewById(R.id.confirm_button).setVisibility(View.GONE);

更多细节

尝试设置确定按钮的可见性消失

SweetAlertDialog sweetdialog = new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE)
.setTitleText("Good job!")
.setContentText("You clicked the button!")
.show();


Button myBtn = (Button) sweetdialog.findViewById(R.id.confirm_button).setVisibility(View.GONE);

您可以使用简单的策略从 sweet alert

访问按钮
SweetAlertDialog alertDialog = new SweetAlertDialog(MainActivity.this,SweetAlertDialog.SUCCESS_TYPE);
alertDialog.setTitleText("Good job!");
alertDialog.setContentText("You clicked the button!");
alertDialog.show();

Button btn = (Button) alertDialog.findViewById(R.id.confirm_button);
btn.setBackgroundColor(ContextCompat.getColor(UserSignupActivity.this,R.color.colorPrimary));

访问后,您可以设置样式或隐藏您的按钮。

使用以下代码代替 new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE)

SweetAlertDialog myDialog = new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE)
.setTitleText("yourtext")
.setContentText("yourtext2")
.show();

myDialog.findViewById(R.id.confirm_button).setVisibility(View.GONE);

您可以将颜色从 color.xml 更改为您想要的十六进制值;

    <color name="blue_btn_bg_pressed_color">#96BFD2</color>
    <color name="blue_btn_bg_color">#AEDEF4</color>
    <color name="button_text_color">#FFFFFF</color>
    <color name="error_stroke_color">#F27474</color>
    <color name="float_transparent">#00000000</color>
    <color name="gray_btn_bg_color">#D0D0D0</color>
    <color name="gray_btn_bg_pressed_color">#B6B6B6</color>
    <color name="material_blue_grey_80">#ff37474f</color>
    <color name="material_blue_grey_90">#ff263238</color>
    <color name="material_blue_grey_95">#ff21272b</color>
    <color name="material_deep_teal_20">#ff80cbc4</color>
    <color name="material_deep_teal_50">#ff009688</color>
    <color name="red_btn_bg_color">#DD6B55</color>
    <color name="red_btn_bg_pressed_color">#CD5B55</color>
    <color name="success_stroke_color">#A5DC86</color>
    <color name="sweet_dialog_bg_color">#FFFFFF</color>
    <color name="text_color">#575757</color>
    <color name="trans_success_stroke_color">#33A5DC86</color>
    <color name="warning_stroke_color">#F8BB86</color>

这也有效

SweetAlertDialog sweetdialog = new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE)
.setTitleText("Good job!")
.setContentText("You clicked the button!")
.show();

 sweetdialog.getButton(SweetAlertDialog.BUTTON_CONFIRM).setBackgroundColor(getResources().getColor(R.color.colorPrimaryDark));