on 2016 Dec 07 3:29 PM
I have label defined as:
<Label id="abelId" text="Some Text" design="Bold" required="true" />
I'm using sap.m.Label.
I would like to change the color of the text (i.e. green) but I don't see anything in the API that allows me to do this. I only see the design property which only changes the font type. Does anyone know how to do this?
Request clarification before answering.
Hi,
You can do it very easily using just one line of CSS only.
First, your view needs to have a Label.

now load the app, open Dev Tools or Ctrl+Shift+I, use Inspector and find the id of the Label,

you will get the Id of the label like this, as __label0-bdi
now this is your id. You can use # with this id and use normal css rules in the styles.css file available in the CSS folder inside your project.

this is your css code.
now load app and check.

when using CSS, dont use other properties in XML, instead of Text (just use minimal properties).
using CSS, add properties to the text, like bold, color, weight, size, and whatever you want.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Ryan,
I tried it using some example I found online but I it still doesn't work.
var labelVar = this.byId("myId");
var xtext = new sap.m.Text({
text: "something"
});
xtext.addStyleClass("fontColors.css");
labelvar.setText(xtext.getText());This the solution I found online through the forums. The program runs with no problems but the color of the text remains the same.
link: embedded css in sapui5
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Eliseo,
I'm not aware of addStyleClass existing as part of the API so you would have to confirm that in the debugger to see if it has extended properties of other jQuery types. If that does not reflect then you can try using the custom CSS as I mentioned or doing a selector with jQuery to add the class you want.
$("myText").css("someclass");
Regards,
Ryan Crosby
Hi Eliseo,
You would have to set some custom CSS for the element or potentially create a custom theme if you want it to be applied globally for all labels.
Regards,
Ryan Crosby
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 18 | |
| 7 | |
| 6 | |
| 6 | |
| 6 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.