Android Question different colors in the text of a label

Andie

Member
Licensed User
Longtime User
I know that parts of a label's text can have different colors. This is done via csbuilder.

But how can I change the color of a certain word, which beforehand is not known, but will be set later by the user?
The structure of a solution could be:

B4X:
Dim text as String = "big problems need big solutions"
Dim word as String = "big" 'is set by user during runtime
Dim colored_text as CSBuilder = ColorChange(text, word, "red")

label.text = colored_text

However, the question is: How can I realize ColorChange?
 

DonManfred

Expert
Licensed User
Longtime User
 
Upvote 0

Andie

Member
Licensed User
Longtime User
Of course I know this tutorial, Manfred. But it doesn't solve my problem.

Maybe I was not clear enough: The part of the label's text, which will have a different color, is not known beforehand. The user, when running the code, should be able to select a word which then is displayed in a different color.
 
Upvote 0

Andie

Member
Licensed User
Longtime User
Okay, I can use Regex.Split with the user's word as split parameter and then put it together like: part1 + word + part2.
My hope was, that a more elegant method would exist.
 
Upvote 0
Top