如何将关闭按钮添加到 SAPUI5 中的 JavaScript 对话框?

How to add a close button to a JavaScript dialog in SAPUI5?

我正在尝试向 javaScript 视图对话框添加一个按钮。 不幸的是,该按钮未显示(Header 按钮) 实际上,我希望对话框的角落有另一个按钮,用于关闭对话框

this.oWarningMessageDialog = new Dialog({
                    type: DialogType.Message,
                    title: this._oBundle.getText("PaymentPostponement"),
                    state: ValueState.Warning,
                    Header: new Button({
                        type: ButtonType.Reject,
                        icon: "sap-icon://decline",
                        press: function (oEvent) {
                            this.oWarningMessageDialog.close()
                            this.oWarningMessageDialog = null
                            Core.byId("ApproveMessageText").destroy()
                        }.bind(this)
                    }),

                    beginButton: new Button({
                        type: ButtonType.Reject,
                        text: this._oBundle.getText("Postpone"),
                        icon: "sap-icon://decline",
                    

如果您需要图像中指定的精确外观,则需要使用 'customHeader' 聚合。代码如下:-

this.oWarningMessageDialog = new Dialog({
                type: DialogType.Message,               
                state: ValueState.Warning,
                customHeader: [
                    new sap.m.Bar({
                       /* either use an icon */
                        contentRight: new sap.ui.core.Icon({
                                src : "sap-icon://decline",
                                useIconTooltip : false,
                                color : "#f33334",
                                press : function (oEvent) {
                                this.oWarningMessageDialog.close();
                                this.oWarningMessageDialog = null;
                                Core.byId("ApproveMessageText").destroy()
                            }.bind(this)
                        }).addStyleClass("sapUiMediumMarginBottom"),
                        /* or you can even use a button */
                        // contentRight: new Button({
                        //  type: ButtonType.Transparent,
                        //  icon: "sap-icon://decline",
                        //  width: "20px",
                        //  press: function (oEvent) {
                        //      this.oWarningMessageDialog.close();
                        //      this.oWarningMessageDialog = null;
                        //  }.bind(this)
                        // }).addStyleClass("sapUiSmallMarginBottom"),
                        contentMiddle : [
                            new sap.m.Title({
                                text :this._oBundle.getText("PaymentPostponement")
                            }),
                            new sap.ui.core.Icon({
                                src : "sap-icon://message-warning",
                                useIconTooltip : false,
                                color : "#E69A17"
                            })
                            ]
                    })

                ],
                    beginButton: new Button({
                    type: ButtonType.Reject,
                    text: this._oBundle.getText("Postpone"),
                    icon: "sap-icon://decline"
                })
            });

或者,包含关闭按钮的正确方法是使用“endButton”聚合。但这将在对话框的页脚显示按钮。