2017-05-24 110 views
2

我正在使用3个按钮进行sap.m.Dialog控件工作,我需要在左侧显示按钮“A”,在中间按钮“B”并按钮“C”在右侧。sap.m.Dialog按钮聚合中按钮之间的空间聚合

请参考下面的代码和截图

enter image description here

Controller.js

var oDialog = new Dialog({ 
    title: "Dialog", 
    type: 'Message', 
    content: new Text({ text: "" }), 
    buttons : [ 
     new sap.m.Button({ 
      text: "A" 
     }), 
     new sap.m.Button({ 
      text: "B" 
     }), 
     new sap.m.Button({ 
      text: "C" 
     }) 
    ], 
    afterClose: function() { 
     oDialog.destroy(); 
    } 
}); 
oDialog.open(); 

我的解决方法

var oDialog = new Dialog({ 
    title: "Dialog", 
    type: 'Message', 
    content: new Text({ text: "" }), 
    buttons : [ 
     new sap.m.Button({ 
      text: "A" 
     }), 
     // below added few dummy buttons to show space like effect at UI 
     new sap.m.Button({text: "", visible:true, enabled:false}), 
     new sap.m.Button({text: "", visible:true, enabled:false}), 
     new sap.m.Button({ 
      text: "B" 
     }), 
     // below added few dummy buttons to show space like effect at UI 
     new sap.m.Button({text: "", visible:true, enabled:false}), 
     new sap.m.Button({text: "", visible:true, enabled:false}), 
     new sap.m.Button({ 
      text : "C" 
     }) 
    ], 
    afterClose: function() { 
     oDialog.destroy(); 
    } 
}); 
oDialog.open(); 

它的外观添加空按钮 enter image description here

我已经添加的按钮与空白的文本后,不知何故,我已经实现显示空格键之间,但这是在加样作用空间正道UI?或者有什么合适的方法来满足我的要求?

+0

您的解决方法是否适用于移动设备? – Marc

+0

它的工作,但用户界面得到了符文,只有一个按钮是可见的右手柄一侧,其余的2按钮有自动隐藏进overflowButton – Prashob

+0

我只是想知道你的“空”按钮显示。 – Marc

回答

1

将与自定义CSS一起工作。插入您的manifest.json的CSS文件,

... 
    "sap.ui5": { 
    ... 
    "resources": { 
     "css": [{ 
     "uri": "css/style.css" 
     }] 
    } 
    } 

的URI的css/style.css文件中创建的style.css。在您的视图中提供按钮ID。在stlye.css中定位带#的按钮。对齐style.css中的按钮。

+0

hi @ n01dea,感谢您的回复,是否有任何解决方法,而不应用css并将边缘类添加到按钮 – Prashob

+0

也许弹出框有助于:https://sapui5.hana.ondemand.com/explored.html#/sample/sap .m.sample.FlexBoxBasicAlignment /预览。请检查中心演示了。然后,只需将左右边距添加到中心的按钮 – n01dea

+0

我也尝试添加sap.m.FlexBox控件,但最终得到未被捕获的错误**未捕获错误:“Element sap.m.FlexBox #__ box0”对于元sap.m.Dialog #__ dialog0的聚合 “按钮” ** '按钮:[ 新sap.m.FlexBox({ 项目:[ \t新sap.m.Button({ \t \t文本:“A “ \t}), \t新sap.m.Button({ \t \t文本: ”B“ \t}), \t新sap.m.Button({ \t \t文字: “C” \t}) ] }) ]' – Prashob

0

编辑: 另一种方法是在对话框的内容聚合中放置一个条形控件。

var dialog = new sap.m.Dialog({ 
      title: "Dialog", 
      type: 'Message', 
      content: 
       new sap.ui.layout.VerticalLayout({ 
        width:"100%", 
        content: [ 
         new sap.m.Text({ 
         text: 'One of the keys to success is creating realistic goals that can be achieved in a reasonable amount of time.'      
         }).addStyleClass("sapUiSmallMargin"), 
         new sap.m.Bar({ 
          design: "Footer", 
          contentLeft: new sap.m.Button({ text: "Button A"}), 
          contentMiddle: new sap.m.Button({ text: "Button B"}), 
          contentRight: new sap.m.Button({ text: "Button C"}) 
         }) 
        ] 
       }), 
      afterClose: function() { 
       dialog.destroy(); 
      } 
     }); 
     dialog.addStyleClass("sapUiNoContentPadding "); 

原来的答案:

您可以用百分比来响应处理其分配的宽度。由于您使用3个按钮,因此可以为每个按钮分配约30%的宽度。这可能会在移动设备上导致一些问题,因为动态添加的边距可以使用标准的“sapUiNoMarginBegin”&“sapUiNoMarginEnd”类删除。

代码段:

buttons : [ 
       new sap.m.Button({ 
        text: "Button A", 
        width:"30%" 
       }).addStyleClass("sapUiNoMarginEnd").addStyleClass("sapUiNoMarginBegin"), 
       new sap.m.Button({ 
        text: "Button B", 
        width:"30%" 
       }).addStyleClass("sapUiNoMarginEnd").addStyleClass("sapUiNoMarginBegin"), 
       new sap.m.Button({ 
        text : "Button C", 
        width:"30%" 
       }).addStyleClass("sapUiNoMarginEnd").addStyleClass("sapUiNoMarginBegin") 
      ], 
+0

不幸的是,它不会在按钮之间添加任何空格。 – Rufi

0

尝试把键 “A” 在聚合beginButton,在聚合endButton聚合buttons和键 “C” 按钮 “B”。

+0

嗨@amiramw,我试着你的解决方法,但我发现你可以在对话框中同时使用beginButton,endButton和按钮聚合,但按钮聚合覆盖beginButton和endButton,所以没有使用它们的要点。 – Prashob

0

@Prashob

使用Flexbox的控制如下:

<FlexBox height="100px" alignItems="Center" justifyContent="Center"> 
       <items> 
        <Button text="Submit" type="Emphasized" width="300px" press="submitDetails"/> 
       </items> 
      </FlexBox> 

你需要根据你需要的按钮来更改justifyContent属性。 对于三个按钮,您将需要3个Flexbox,它将包含每个按钮。也许把它们放在一边可以使用HBOX控制。

   <HBox> 
        <items> 
         <FlexBox id="fb1" height="100px" alignItems="Center" width="400px" justifyContent="SpaceAround"> 
          <items> 
           <Button id="b1" text="Start" width="200px"/> 
          </items> 
         </FlexBox> 
         <FlexBox id="fb2" justifyContent="Center" height="100px" alignItems="Center" width="400px"> 
          <items> 
           <Button id="b2" text="Center" width="200px"/> 
          </items> 
         </FlexBox> 
         <FlexBox id="fb3" justifyContent="End" height="100px" width="400px" alignItems="Center"> 
          <items> 
           <Button id="b3" text="End" width="200px"/> 
          </items> 
         </FlexBox> 
        </items> 
       </HBox> 

检查的如下上面的代码的输出: output

可以将justifyContent属性相应地改变和按钮,并flexboxes的宽度,以获得期望的结果。

+0

嗨@loki,感谢您的回复,但我无法使用FlexBox或HBox作为对话框的按钮聚合。即使我使用它,我最终会在屏幕上出现错误,因为sap.m.Button是sap.m.Dialog的按钮聚合中唯一可以使用的控件。 – Prashob

+0

@Prashob哦,我没看到sap.m.Dialog。我还没有使用过Dialog控件,我也是SAPUI5的新手。如果我找到一些我会再次发布。 – loki

+0

@Prashob按钮没有聚合,这是令人沮丧的xD他们有leftButton和RightButton关联,但现在不推荐使用它。 – loki