Android Question using a special font in my app

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
it may be a lame question but i'll ask it

in my app there is a textbox i want to use with a special font not a part of the system (in windows it is "OCR A")
is there a way i can use it?
thanks
 

MarcoRome

Expert
Licensed User
Longtime User
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
thanks
i wanted to use an external font
but if it comes with some pain i think i'll drop the idea
i did see an app that uses that external font so i wondered how can i do it myself too
once again - thanks
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Simple, I use non standard fonts all the time.

Add the font into your assets folder, like any other asset.



Then assuming your view is a b4xfont
B4X:
' if your view is a standard view, like label

lbl.typeface = typeface.loadfromAsset("fontname")

'if your view is a b4xview
lbl.font = xui.createfont(typeface.loadfromAsset("fontname"),<size of font>)

edited for clarity.
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
sorry for the super lame - how do i add the file and where is that folder?
or folder name

thanks
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
My mistake, the actual command has a "s" on the end "loadfromassets". I was typing from memory.

Also you need the full filename of the font file including any extension.
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
My mistake, the actual command has a "s" on the end "loadfromassets". I was typing from memory.

Also you need the full filename of the font file including any extension.
one more question regarding font - can i use the same way on spinner?
i also wish to change spinner's font...

thanks
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
What have you tried?
Does spinner have a font property?
Does the spinner expose a label or other view that has a font property?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Spinner has no font property
Here is an example where you can use csbuilder and your font file:
B4X:
Dim MyList As List
    MyList.Initialize
    MyList.AddAll(Array  ("Monday","tuesday","Friday","test2", "Zeev"))
    Dim myFont As Typeface = Typeface.LoadFromAssets("mtcorsva.ttf")   'use your font file
    Dim cs As CSBuilder
    For i = 0 To MyList.Size -1
        Spinner1.Addall(Array(cs.Initialize.Size(30).color(Colors.Red).Typeface(myFont).Append(MyList.Get(i)).PopAll))
    Next
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
Thanks, will try
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
OK
now there is a need to answer
your sample works beautifully
thank you
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…