Android Question Name of Font in Use

Del

Member
Licensed User
Longtime User
My wife came back from the phone store with a new Samsung A5 last week (with Marshmallow) whose font size had been set to Huge and whose Style had been set to Gothic Bold by them because she complained about being unable to read the new phone contacts list without her glasses.

So it was a huge surprise to me that when I installed my perfect 4.41 rated app, which has had thousands of downloads, it looked like complete rubbish with giant text spilling out all over the place.

I partially solved the size problem with the Accessiblity (sic) library which provides the useful GetUserFontScale factor which enables me to rescale label text sizes, but the problem is that I cannot over-ride the Font Style using :-

B4X:
Label1.Typeface  = Typeface.CreateNew (Typeface.DEFAULT, Typeface.STYLE_NORMAL)

This may be because I do not understand what 'DEFAULT' means in this context so would appreciate enlightenment from someone who knows better. Is it possible to get the name and other properties of the device default font ?
I got 'android.graphics.Typeface@d8c81ed8' when I did 'Log(lblGeography.Typeface)'. Is this a clue ?

The effect is obvious if you change the font to 'Rosemary'.

The next line DOES work, it changes the font to Monospace :-

B4X:
Label1.Typeface  = Typeface.CreateNew (Typeface.MONOSPACE, Typeface.STYLE_NORMAL)

However the Monospace font makes my app look badly old fashioned.

I think the way forward for me unless someone has a better idea is to load my own font into each view in my app, which I may find painful. My question then is 'Which one ?'

My other question is more general. I have a lot of users in Russia who never complain but I now wonder if their DEFAULT font style is indeed Russian and they are having to set their devices to the Latin alphabet ?. And this may explain why I have had some strange reviews from Indonesia?

Regards Del +++
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I don't think that it is possible to find the name of the default font. Typeface.DEFAULT means that the default font will be used.

My other question is more general. I have a lot of users in Russia who never complain but I now wonder if their DEFAULT font style is indeed Russian and they are having to set their devices to the Latin alphabet ?. And this may explain why I have had some strange reviews from Indonesia?
You don't need to worry about it as the default font will always include Latin characters.
 
Upvote 0

Del

Member
Licensed User
Longtime User
Many thanks Erel for your reply. I am reassured.

The original cause of my confusion was that the default font had been replaced by a slightly different non-cursive font that looked like the default. I have been looking at this issue in more detail. Here is some code that makes four rows of labels with the different built in fonts and with four columns each of the different font styles.

B4X:
Sub MakeLabel (oLabel As Label, sText As String,  fLeft As Float, fTop As Float, oTypeface As Typeface, nStyle As Int) As Label
    oLabel.Initialize ("")
    oLabel.Text      = sText
    oLabel.TextSize  = 24  
    oLabel.Textcolor = Colors.black
    oLabel.Color     = Colors.white
    oLabel.Typeface  = Typeface.CreateNew (oTypeface,  nStyle)
    Activity.AddView (oLabel,  fLeft, fTop,   20%x, 15%y)
    Return oLabel
End Sub
Sub Activity_Resume
    Activity.RemoveAllViews
    Private oTypefaces () As Typeface = Array As Typeface (Typeface.DEFAULT, Typeface.SANS_SERIF, Typeface.SERIF, Typeface.MONOSPACE)
    Private nStyles () As Int = Array As Int (Typeface.STYLE_NORMAL, Typeface.STYLE_BOLD, Typeface.STYLE_ITALIC, Typeface.STYLE_BOLD_ITALIC)
    Private LabelArray (4) As Label
    For nRow = 0 To 3
        For nColumn = 0 To 3
            LabelArray (nRow) = MakeLabel (LabelArray (nRow), "ABCdef",  nColumn * 25%x, nRow * 20%y, oTypefaces (nRow),  nStyles (nColumn) )
        Next
    Next
    Dim r As Reflector ' needs library
    Private sOS As String = "OS=" & r.GetStaticField ("android.os.Build$VERSION", "SDK_INT")
    Private lblInformation As Label
    MakeLabel (lblInformation, sOS,  0, 85%y, oTypefaces (1),  nStyles (1) )
End Sub

I have four Samsung devices in which I changed the font in settings to Rosemary to make the effect obvious. See the screenshots.

In summary the older phones with OS versions 19 and 18 were unable to apply font styles bold, italic and bold italic to the Monospace font whereas the newer phones with OS 21 and 23 were able to do so.

However in contrast, and far more seriously, the newer phones with OS 21 and 23, instead of applying the Sans Serif font, incorrectly applied the Rosemary font, but correctly applied bold and italic to the Monospace font.

I am no longer confused, just mystified, this is surely a bug in the OS and I am sharing this in case someone finds it useful.

My other idea of gaining control by loading a known font for all labels from the Assets folder works very well but I need to find a non-copyrighted free font that looks like Arial for my free app.

Regards Del +++

AndroidFontTest.png
 
Last edited:
Upvote 0
Top