Android Custom Fonts

7 replies [Last post]
AParachutingFrog's picture
AParachutingFrog
User offline. Last seen 4 days 21 hours ago. Offline
Joined: 13 Nov 2011

I have read through a few topics on the API and forums about custom fonts and android.

I have the following which works fine on Apple devices:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
settings =
{
        orientation =
        {
                default = "landscapeRight",
                supported =
                {
                        "landscapeRight",
                },
        },
        
        iphone =
        {
                plist =
                {
                        UIAppFonts = 
                        {
                                "MyFont.ttf"
                        },
 
                        UIStatusBarHidden=true,
                        UIPrerenderedIcon = true
 
 
                        
                },
        }
               
}

It states that you don't need to specify for Android and I have check that the fontname (not the file) name is the same as it is in FontBook on my PC using native.getFontNames() and indeed the name is the same.

However, when using my font I get Warning: could not load font MYFONTNAME. Using default font.

Is in fact the documentation misleading and there is something else I need to be doing?

Replies

AParachutingFrog's picture
AParachutingFrog
User offline. Last seen 4 days 21 hours ago. Offline
Joined: 13 Nov 2011

Ignore me. Font wasnt installed on PC :)

nick_sherman's picture
nick_sherman
User offline. Last seen 1 week 4 days ago. Offline
Joined: 23 Sep 2011

I was wrestling with this last night. I have discovered that on Android, you specify the filename, MINUS the file extension.

i.e. "amienne.ttf" becomes "amienne" for Android, while on iOS it would be "Amienne".

Also make sure the actual font file is in the root folder of your project.

AParachutingFrog's picture
AParachutingFrog
User offline. Last seen 4 days 21 hours ago. Offline
Joined: 13 Nov 2011

Thanks for the response

How does your build.settings file look if you dont mind sharing

nick_sherman's picture
nick_sherman
User offline. Last seen 1 week 4 days ago. Offline
Joined: 23 Sep 2011

Sure...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
settings =
{
 
        androidPermissions =
   {
       "android.permission.VIBRATE"
   },
 
        orientation =
        {
                default = "landscapeRight",
                                content = "landscapeRight",
                                supported =
                                        {
                                        "landscapeRight"
                                        },
        },
 
        iphone =
        {               
                 plist =
                {
                                
                                MinimumOSVersion="4.3", 
                                UIApplicationExitsOnSuspend = false,
                                UIAppFonts = 
                        {
                                "amienne.ttf",
                                "teen.ttf"
                        },
 
                                CFBundleURLTypes =
            {
                {
                    CFBundleURLSchemes =
                    {
                        "fb363179733694583",
                    }
                }
            },
                        CFBundleIconFile = "Icon.png",
                        CFBundleIconFiles = {
                                "Icon.png" , 
                                "Icon@2x.png" , 
                                "Icon-72.png" , 
                                "Icon-Small-50.png" , 
                                "Icon-Small.png" , 
                                "Icon-Small@2x.png"
                        },
                },
        }
}

AParachutingFrog's picture
AParachutingFrog
User offline. Last seen 4 days 21 hours ago. Offline
Joined: 13 Nov 2011

thanks for that

So when you say you are missing the TTF off you mean in code when specifying a newText object?

nick_sherman's picture
nick_sherman
User offline. Last seen 1 week 4 days ago. Offline
Joined: 23 Sep 2011

Yes, I just set up a table called fontName and set the values depending on system.getInfo("platformName").

AParachutingFrog's picture
AParachutingFrog
User offline. Last seen 4 days 21 hours ago. Offline
Joined: 13 Nov 2011

Thanks again for your help thats clear

Viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.