Page 1 of 1

Setting a custom font on Android

Posted: Thu Feb 14, 2019 8:00 pm
by Monox18

I'm following the lesson to set up a custom password font: ... word-field

but I get an error "Can't load font file". So, it works in the IDE and Windows standalone but not in Android. Any help?

My code is on a preOpenStack handler and I added the PasswordEntry.ttf file on the standalone settings "Copy Files". The file is on the same folder as the stack.

Code: Select all

on preOpenStack
   local theFontFile, theError
   set the itemdelimiter to slash
   put the effective filename of this stack into theFontFile
   delete the last item of theFontFile
   put theFontFile & "/PasswordEntry.ttf" into theFontFile
   start using font file theFontFile
   put the result into theError
   if theError is not empty then
      answer "Error loading password font:" &cr& theError & "."
   end if
end preOpenStack

Re: Setting a custom font on Android

Posted: Fri Feb 15, 2019 8:25 am
by AxWald

putting the .ttf into a "fonts" folder next to your stack & referring it in the "Copy Files" section of the SA settings as "fonts/*" is all that's needed. It ends in "YourApp.apk/assets/fonts/" then.

The font is available for your app this way as if it was installed on the machine.
The same works for .ogg ("sounds folder).

So you can skip the "Loading The Font" section of the tutorial (in case of Android), it's of no use here. Just having the .ttf in the appropriate folder does the job for you already ;-)

Have fun!

Re: Setting a custom font on Android

Posted: Mon Feb 18, 2019 9:59 pm
by Monox18
Thanks AxWald. Your suggestion worked.