cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 - StandardListItem icon color

Former Member
0 Kudos

Hello, I am trying to change color of an icon of a StandardListItem.

On press function, I want to create a new icon and set it to the StandardListItem object.

detailPressed: function(oEvent) {
var oIcon = new sap.ui.core.Icon({
src : "sap-icon://alert",
color: "#333333"
});

oEvent.getSource().setIcon(oIcon.getSrc());
}

But since setIcon method of StandardListItem takes only URI of the icon, color is not taken into account. Could you please tell me how to change color icon?

Thank you.

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member227918
Active Contributor
0 Kudos

you approach is wrong, check the link below may help you:

https://jsfiddle.net/Akhilesh_U/yu919sw3/

0 Kudos

Two options:

1)

Use expression binding for the src and color https://help.sap.com/saphelp_uiaddon10/helpdata/en/da/f6852a04b44d118963968a1239d2c0/content.htm and update the model. Once the model is updated onPress, the icon and color will be updated

<core:Icon
    src="{= ${pressed} === '0' ? 'sap-icon://sys-enter' : 'sap-icon://alert' }"
    color="{= ${pressed} === '0' ? 'green' : 'red' }"
    tooltip="{= ${pressed} === '0' ? ${i18n>unpressed} : ${i18n>pressed} }"
/>

2)

Use a string for color like "red" with the previous code but instead of adding a new Icon, reconfigure the existing one.