2017-05-24 114 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