Android Question set default font

yaniv hanya

Active Member
Licensed User
Another beginner's question.
I have a certain font that I need to use.
Where do I put his files?
And how do I set it to be the default font of the entire application?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can set the font with the designer. Add the font file to the designer files and then switch the Typeface.

You can also do it programmatically:
B4X:
Dim fnt As Typeface  = Typeface.CreateNew(...)
For Each v As View In Activity.GetAllViewsRecursive
   If v Is Label Then
       Dim lbl As Label = v
       lbl.Typeface = fnt
   End If
Next

This exact code will work with EditText, Button, Label, CheckBox, RadioButton and ToggleButton as well as they are subtypes of label.
 
Upvote 0

yaniv hanya

Active Member
Licensed User
Thanks. I'll try it.
But is there a way to determine that this font will be the default?
After all, the controls are created in the designer with the value at default
and not with a reference to a particular font.
 
Upvote 0

Brandsum

Well-Known Member
Licensed User
Replace that with the base theme you are using for your app. If you cant figure it out then post your manifest.
 
Upvote 0

yaniv hanya

Active Member
Licensed User
this is the msnifest
 
Upvote 0

Brandsum

Well-Known Member
Licensed User
B4X:
CreateResource(values, theme.xml,
<resources>
    <style name="MyTheme" parent="android:Theme.Holo">
        <item name="android:fontFamily">@font/CustomFontStyle</item>
        <item name="fontFamily">@font/CustomFontStyle</item>
    </style>
</resources>
)
SetApplicationAttribute(android:theme, "@style/MyTheme")
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…