Android Question How to assign to label font Times new roman ?

b4auser1

Well-Known Member
Licensed User
Longtime User
A customer doesn't like font by default for labels. In Designer there is very limited list of fonts to select.
DEFAULT, SANS SERIF and MONO SPACE. How to assign f.e. Time new roman ?
 

Cableguy

Expert
Licensed User
Longtime User
It depends how your design was created, if you created it using the internal designer then you need to add the font file to the files tab, and you will then be able to see it under the font property...
If you are creating your layout by code, then you need to add the font file to the files tab and in your code ...
B4X:
Dim myFont as typeface
myFont=myFont.newtypeface(myFont.loadfrofile(.....)
Obs. This is pseudo code, not tested, written from memory, so some adapting may be needed
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
[edit] - @Cableguy beat me to it ;)

The fonts that are available are the only ones that come "with the OS" (or are supplied by B4A).

If you want a different font you will need to find a TTF or OTF version of the font and include it in your files folder. Once there, you may add it via the files tab on the designer and you will then see it in the designer font list. Note that Android can be kind of picky with its font files, I have had some TTF files that work fine on Windows machines yet fail to load properly on Android devices.

Or, you can create the typeface in your starter service and assign it manually:
B4X:
Public TimesFont As TypeFace

Sub Service_Create
  TimesFont = Typeface.LoadFromAssets("times.ttf")
End Sub

Then, in your code you can set it via
B4X:
  Label1.Typeface = Starter.TimesFont
 
Upvote 0
Top