Android Question Can Android system font be changed?

Sergio Castellari

Active Member
Licensed User
Hello,
Can the android system font be read, and if it is different from the default, change it for our application?
I need my application to work with the default font.
Greetings,
Sergio
 

TILogistic

Expert
Licensed User
Longtime User
Last edited:
Upvote 0

Sergio Castellari

Active Member
Licensed User
Not sure that I understand. You cannot change the system font.
Hello, I want my APP to always have the same font size (default), even if the end user changes the font size on their android device. I use Google Translator (my language is Spanish) Greetings,
Sergio

Hola,
Quiero que mi APP, tenga siempre el mismo tamaño de fuente (predeterminada), aunque el usuario final cambie el tamaño de fuente en su dispositivo android.
Utilizo Google Traductor (mi lengua es el español)

Saludos,
Sergio
 
Upvote 0

Sergio Castellari

Active Member
Licensed User
Fonts the you APP
https://stackoverflow.com/questions/16404820/how-to-set-default-font-family-for-entire-android-app
https://www.b4x.com/android/forum/threads/theme-colors.87716/#content
Sample:
XML:
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")
Hi @oparra Does this code go in the manifest? What does he do? My intention is that my APP always has the same size even if the end user changes the font to a larger or smaller size. Thank you in advance for your help !!! Greetings,

Hola @oparra
¿Este codigo va en el manifiesto? ¿Que es lo que hace?
Mi intencion es que mi APP, tenga siempre el mismo tamaño aunque el usuario final, cambie la fuente a un tamaño mas grande o mas chico.
Desde ya gracias por tu ayuda!!!
Saludos,
Sergio
 
Upvote 0

Sandman

Expert
Licensed User
Longtime User
My intention is that my APP always has the same size even if the end user changes the font to a larger or smaller size.
Have you really thought this through? I mean, if the user made the OS font size larger (for instance), they probably want it larger. Like, they might have bad eyesight, or something like that. Do you expect them to be happy when your app didn't respect their wishes..?
 
Upvote 0

Sergio Castellari

Active Member
Licensed User
Have you really thought this through? I mean, if the user made the OS font size larger (for instance), they probably want it larger. Like, they might have bad eyesight, or something like that. Do you expect them to be happy when your app didn't respect their wishes..?

Hi @Sandman !!! I understand. The end user can configure the font size they want. But my application will have the font that I determine.
 
Upvote 0

Sergio Castellari

Active Member
Licensed User
Well, there are several posts in the forum on how to set a custom font for your app so it should be simple to find with the search engine.
Thanks @Sandman, Mr. @oparra indicated some changes in the manifest, but when applying them he gives me an error (which obviously I do not know what it is about). It seems that I am missing a file.
Attached compilation capture
Thank you again

Gracias @Sandman ,
El señor @oparra me indico unos cambios en el manifiesto, pero al aplicarlos me da error (que obviamente no se de que se trata). Pareciera ser que me falta un archivo.
Adjunto captura de compilacion
Nuevamente gracias

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")
 

Attachments

  • errorB4A.png
    errorB4A.png
    16.4 KB · Views: 122
Upvote 0

Dave O

Well-Known Member
Licensed User
Longtime User
Yes, you can cancel the effects of a system-font-size change in your app.

B4X:
Public access As Accessibility
Public systemFontScale As Float = access.GetUserFontScale
...
somebutton.TextSize = somebutton.TextSize / systemFontScale

Basically, we get the system's font scaling (e.g. 1.5 for a larger-than-normal font), then we divide a widget's textSize by that same factor, canceling the system's font-size change.

In general, we should respect the user's choice of bigger (or smaller) font size, but it also can make it very hard for developers to present a tidy and consistent UI at the same time. So I've compromised with this hybrid approach:
- Text that is tight for space (e.g. title bars, checkbox text that might wrap, etc.) gets "de-scaled" as shown above, so that it's the size I designed.
- All other text (e.g. text-input fields, multi-line labels and fields, etc.) follows the user's desired scaling (by not canceling it).
- I give the user an explicit way to control the size of layouts (e.g. small/normal/large), so I can scale not only the text size but also the spacing of list items, etc.).

This takes some code, but it's not hard and it results in an app that offers smaller/larger layouts as desired, without making the app looks messy at really big system-font sizes.

Hope this helps!
 
Upvote 0

Sergio Castellari

Active Member
Licensed User
Yes, you can cancel the effects of a system-font-size change in your app.

B4X:
Public access As Accessibility
Public systemFontScale As Float = access.GetUserFontScale
...
somebutton.TextSize = somebutton.TextSize / systemFontScale

Basically, we get the system's font scaling (e.g. 1.5 for a larger-than-normal font), then we divide a widget's textSize by that same factor, canceling the system's font-size change.

In general, we should respect the user's choice of bigger (or smaller) font size, but it also can make it very hard for developers to present a tidy and consistent UI at the same time. So I've compromised with this hybrid approach:
- Text that is tight for space (e.g. title bars, checkbox text that might wrap, etc.) gets "de-scaled" as shown above, so that it's the size I designed.
- All other text (e.g. text-input fields, multi-line labels and fields, etc.) follows the user's desired scaling (by not canceling it).
- I give the user an explicit way to control the size of layouts (e.g. small/normal/large), so I can scale not only the text size but also the spacing of list items, etc.).

This takes some code, but it's not hard and it results in an app that offers smaller/larger layouts as desired, without making the app looks messy at really big system-font sizes.

Hope this helps!
Excellent Mr. @Dave O !!! ... This is exactly what I wanted ... I wanted my home screen to look the same on devices with different default sizes. It was very easy to apply:

MAIN:
Public access        As Accessibility
Public pSysFontScale As Float = access.GetUserFontScale

B4XMainPage:
'Ajusto tamaños de fuentes SIN importar el tamaño de fuente elegida por el Usuario...
Label1.TextSize = Label1.TextSize/Main.pSysFontScale
Label2.TextSize = Label2.TextSize/Main.pSysFontScale
CheckBox1.TextSize = CheckBox1.TextSize/Main.pSysFontScale
btnSalir.TextSize = btnSalir.TextSize/Main.pSysFontScale
btnAcceder.TextSize = btnAcceder.TextSize/Main.pSysFontScale
EditText1.TextSize = EditText1.TextSize/Main.pSysFontScale
EditText2.TextSize = EditText2.TextSize/Main.pSysFontScale

Thanks a lot! A big hug
 
Upvote 0
Top