Android Question Set font scale to Large

cooperlegend

Active Member
Licensed User
Longtime User
Hi, does anyone know a method to set the font scale to large via code ?

Thanks in advance

John
 

ilan

Expert
Licensed User
Longtime User
hi

do you mean to change the font size in android settings through your app? or change the font size only for your app?
 
Last edited:
Upvote 0

cooperlegend

Active Member
Licensed User
Longtime User
Hi

I have a requirement to change the font scale in the android settings, but this needs to be done by code.

The customer has a large number of devices which need setting up so running this as part of setup rather than manually having to do this is desired :)

Thanks

John
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
i know that u can get the font size via Accessiblity lib but change it i guess you could do it via JavaObject

this is the code to get the fontscale

B4X:
Dim fscale As Double
Dim access As Accessiblity 
    
fscale = access.GetUserFontScale
 
Upvote 0

cooperlegend

Active Member
Licensed User
Longtime User
Yes. Reading is not a problem.
Writing is. I don't code in java so I am not sure what is needed.
Any help please?
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Got it, thanks to @corwin42 : https://www.b4x.com/android/forum/threads/phone-display-brightness.13021/#post-83857

Needs :
- Phone (only for example)
- Reflection library

And in the Manifest
B4X:
AddPermission("android.permission.WRITE_SETTINGS")

Call
B4X:
Dim P As Phone
Log($"Current: ${P.GetSettings("FONT_SCALE")}"$)

    Dim value As Float = 4
    WriteSetting("FONT_SCALE", value)

Log($"After: ${P.GetSettings("FONT_SCALE")}"$)

B4X:
Sub WriteSetting(Setting As String, Value As Float)
   Dim r1 As Reflector
   Dim args(3) As Object
   Dim types(3) As String

   r1.Target = r1.GetContext
 
   args(0) = r1.RunMethod("getContentResolver")
   types(0) = "android.content.ContentResolver"
   args(1) = Setting
   types(1) = "java.lang.String"
   args(2) = Value
   types(2) = "java.lang.float"
   r1.RunStaticMethod("android.provider.Settings$System", "putFloat", args, types)
End Sub
 
Upvote 0

cooperlegend

Active Member
Licensed User
Longtime User
Excellent, many thanks for all your help with this one :)

I actually wrote this into a library just as a learning exercise.

It works fine after device is rebooted.

Only issue is that even though the font is larger, the system settings screen still shows "Tiny"
 
Upvote 0
Top