Android Question Set Custom Font label only for an interval of character

Mike1970

Well-Known Member
Licensed User
Longtime User
Hi everyone, I'd like to know if there is a way to set a custom font only for a determinate interval of character.

I currently use CustomFonts library to change the typeface with a .tff
But i need to compose a string containing a fontawesome character:

You are Ready ✔


"You are Ready" has to be with a custom font, and the "✔" has to be a fontawesome character


I tried
B4X:
lblTitleTB2.Typeface = MyriadTitle.SetCustomFonts
Dim rs2 As RichString
Dim rs2b As RichStringBuilder
rs2b.Initialize
rs2.Initialize($"You are Ready %gr%${Chr(0xF058)}%gr%"$)
rs2.Color2(0xFF6FDA8E, "%gr%")
rs2.Style(rs2.STYLE_BOLD,0, rs2.Length)
rs2b.Append(rs2)
lblTitleTB2.Text = rs2b
 

Mike1970

Well-Known Member
Licensed User
Longtime User
I had an illumination, but i leave the post, maybe can be useful to someone.

i solved with:


B4X:
    rs2.TypefaceCustom(Typeface.LoadFromAssets("Myriad Pro Bold.ttf"), 0, rs2.Length-1)
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I had an illumination, but i leave the post, maybe can be useful to someone.
You can also accomplish what you wanted using csbuilder which is more modern that richstring:
B4X:
Dim cs As CSBuilder
 lblTitleTB2.Text = cs.Initialize.size(30).Color(Colors.red).Typeface(Typeface.loadfromassets("Myriad Pro Bold.ttf")). _
    Append("You are Ready ").Typeface(Typeface.FONTAWESOME).Append(Chr(0xF058)).PopAll
You can use a different size and color or remove the size and color part if you wanted.
 
Upvote 0
Top