• 如何操作SAP UI5应用Footer区域工具栏按钮的背景颜色


    Recently I get a customer requirement to remove the background color of edit button in footer toolbar:

    The expected behavior:

    The screenshot is made from CRM Fiori application “My Opportunity”. Customer are using it in their Android device. They complained since the button in Android platform will have blue as its background color automatically when clicked, so it is difficult to judge whether a button with blue background itself is actually clicked or not.

    Here below is my analysis process how to achieve the customer requirement.

    (1) First of all, we need to figure out how the blue background color is implemented in the standard application. Check related controller code regarding footer toolbar button definition, and there is no style definition regarding Edit button. So it must definitely be done by UI5 framework.

    Use Chrome development tool, figure out which native html element is responsible for edit button rendering.

    And then we find this CSS class div.sapMBtnInner.sapMBtnEmphasized has controlled the button style.

    It should easily be verified, since we de-select the checkbox for property “background-color” and the appearance of Edit button is just what we expect.

    (2) Now we need to know how this CSS style is added by UI5 framework. Search by keyword “Emphasized” and I just find what I look for in a second. In line 80 there is an IF evaluation to check the availability of oEditBtn of variable oController._oHeaderFooterOptions, whose value is filled by we application code.
    It means if application has explicitly declared the edit button, it is set with style = Emphasized automatically in line 87.

    Then solution is found: just manipulate the oHeaderFooterOptions by implementing extension hook:

    extendHeaderFooterOptions : function(oHeaderFooterOptions) {
         var that = this;
         oHeaderFooterOptions.buttonList.splice(0, 0, {sI18nBtnTxt : "EDIT",
          onBtnPressed : function(evt) {
              that.onEdit();
          },
          bEnabled : true
          });
          oHeaderFooterOptions.oEditBtn = null;
        },
    

    The idea is to clear the oHeaderFooterOptions.oEditBtn manuall so that the IF evaluation in line 80 will not succeed, and then we jut define the Edit button as “normal” button by inserting it into the array oHeaderFooterOptions.buttonList.
    However while testing, it is found that every time you navigate to Edit mode and then back, there will be a new Edit button generated in toolbar.

    The solution is to simply introduce a Boolean variable to ensure the Edit button insertion is only executed once:

    extendHeaderFooterOptions : function(oHeaderFooterOptions) {
         if( this.bEditButtonDefined)
          return;
         this.bEditButtonDefined = true;
         var that = this;
         oHeaderFooterOptions.buttonList.splice(0, 0, {sI18nBtnTxt : "EDIT",
          onBtnPressed : function(evt) {
              that.onEdit();
          },
          bEnabled : true
          });
          oHeaderFooterOptions.oEditBtn = null;
        }
    

    If you would like to change the button’s background color to any other color, please refer to this blog: How to change the background color of button in Footer area

    要获取更多Jerry的原创文章,请关注公众号"汪子熙":

  • 相关阅读:
    《柯尔特思维教程》-第6章(行动)- 第7节:解决方案
    《柯尔特思维教程》-第6章(行动)- 第6节:输入
    《柯尔特思维教程》-第6章(行动)- 第5节:思维的目的
    《柯尔特思维教程》-第6章(行动)- 第4节:TEC
    《柯尔特思维教程》-第6章(行动)- 第3节:缩小
    《柯尔特思维教程》-第6章(行动)- 第2节:扩展
    《柯尔特思维教程》-第6章(行动)- 第1节:目标
    《柯尔特思维教程》-第5章(信息和情感)- 第10节:SF&CF:简化和澄清
    Oracle-日常运维-删除临时文件回收空间
    OGG-Oracle 集成模式抽取进程,REGISTER DATABASE都做了什么?
  • 原文地址:https://www.cnblogs.com/sap-jerry/p/13625739.html
Copyright © 2020-2023  润新知