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
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="b4a.example"
android:versionCode="1"
android:versionName=""
android:installLocation="internalOnly">

<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<application
android:icon="@drawable/icon"
android:label="bar 5"
android:theme="@style/DarkTheme">
<activity
android:windowSoftInputMode="stateHidden"
android:launchMode="singleTop"
android:name=".main"
android:label="bar 5"
android:screenOrientation="unspecified">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

</activity>
<service android:name=".starter">
</service>
<receiver android:name=".starter$starter_BR">
</receiver>
<activity
android:windowSoftInputMode="stateHidden"
android:launchMode="singleTop"
android:name=".homescreen"
android:label="bar 5"
android:screenOrientation="unspecified">
</activity>
<activity
android:windowSoftInputMode="stateHidden"
android:launchMode="singleTop"
android:name=".photosact"
android:label="bar 5"
android:screenOrientation="unspecified">
</activity>
<activity
android:windowSoftInputMode="stateHidden"
android:launchMode="singleTop"
android:name=".setbackground"
android:label="bar 5"
android:screenOrientation="unspecified">
</activity>
<activity
android:windowSoftInputMode="stateHidden"
android:launchMode="singleTop"
android:name=".settingsscreen"
android:label="bar 5"
android:screenOrientation="unspecified">
</activity>
<activity
android:windowSoftInputMode="stateHidden"
android:launchMode="singleTop"
android:name=".installact"
android:label="bar 5"
android:screenOrientation="unspecified">
</activity>
<activity
android:windowSoftInputMode="stateHidden"
android:launchMode="singleTop"
android:name=".waterscreen"
android:label="bar 5"
android:screenOrientation="unspecified">
</activity>
</application>
</manifest>
 
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
Top