cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

how to change the font color of Label

Former Member
0 Kudos
10,173

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?

Accepted Solutions (0)

Answers (3)

Answers (3)

avisheksharmacoder
Participant
0 Kudos

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.

0761
Newcomer
0 Kudos
Very Good!
Former Member
0 Kudos

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

Ryan-Crosby
Active Contributor
0 Kudos

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

Ryan-Crosby
Active Contributor
0 Kudos

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