Android Question How to add Two Typefaces in a single Label

shashkiranr

Active Member
Licensed User
Longtime User
Hi,

I have three lines of text for a label. For the 1 line i want to add a custom Typeface(first.ttf) and for the 2 and 3 line i want to keep it default. Is there any way i can do this?.

Regards,
SK
 

Mahares

Expert
Licensed User
Longtime User
Have you looked at the RichString library. here is a small example that may put you in the right path, although if you load a font, I think it has to be applied to the entire label:
B4X:
Dim rs As RichString
  Activity.AddView(Label2, 10dip, 70dip, 300dip, 300dip)
  rs.Initialize("{R}{T}{Green}First line{Green}{T}{R}" & CRLF & "{U} Second line {U} " & CRLF & "{Red}{BI}Third line{Red}{BI}") 
  rs.Color2(Colors.Green,"{Green}")
  rs.RelativeSize2(2, "{R}")
  rs.Typeface2("monospace", "{T}")
  rs.Underscore2("{U}")
  rs.Color2(Colors.Red, "{Red}")
  rs.Style2(rs.STYLE_BOLD_ITALIC, "{BI}")
  Label2.Text = rs
 
Upvote 0

derez

Expert
Licensed User
Longtime User
Here is an example of a class (just the skeleton) that does it, by using 3 labels. You should add methods for properties that you want to change from the calling module, and put the rest of the prperties directly in the initialization sub of the class.
upload_2014-10-18_9-17-0.png
 

Attachments

  • X3label.zip
    6.8 KB · Views: 173
Upvote 0
Top