Android Question Prevent text zoom

Mike1970

Well-Known Member
Licensed User
Longtime User
Hi everyone,
while testing my app, i noticed that when an user has the text zoom enabled in phone settings, all the sizes of my app are messed up.

Is there a way to prevent the phone to change the sizes I set even if the zooming option is enabled in the settings of the phone?

Thanks in advance
 

Mike1970

Well-Known Member
Licensed User
Longtime User
You can call ResetUserFontScale: https://www.b4x.com/android/forum/threads/spinners-and-extra-large-font-size-scale.73374/#content
It is probably a mistake as the user choose to increase the text size for a reason.
it's because i already made the app with the right size of texts... so i don't want the user to zoom even more... the app became unusable. Or in some cases i used labels to put icons with MaterialDesign or FontAwesome... so that text zooms so much that is cutted out from the hitbox of the object.

Is there way to prevent from Android, or i've to call that function in all the pages? my problem is that is use a lot of objects from libraries or classes...
 
Last edited:
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
You will need to do it in all pages.
Ok Erel, thanks.
I'm trying to implement this function.

However i'm experimenting some issues.
The code i use is this:

B4X:
Sub ResetUserFontScale(p As Panel)
    For Each v As B4XView In p
        If v Is Panel Then
            ResetUserFontScale(v)
        
        Else If v Is Label Then
            Dim lbl As Label = v
            'Log(lbl.Text)
            'Log(access.GetUserFontScale)
            'Log(GetType(v))
            lbl.TextSize = lbl.TextSize / access.GetUserFontScale
    
        Else if v Is AutoTextSizeLabel Then
            Dim albl As AutoTextSizeLabel = v
            albl.BaseLabel.TextSize = 0
        End If
    Next
End Sub

in the layout there are some AutoTextSizeLabels... but seems that them are classfied as "Label" and then the method "TextSize" does not do anything because it does not exists for them, but you should do: AutoTextSizeLabel1.BaseLabel.TextSize but i can't do this becuase i'm not able to distinguish between actual Labels and AutoTextSizeLabels.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
What about if you try to involve the Tag property. Something like this works, but I have not applied it to accessibility to see if it works. In designer put 0 in the regular label tag and 1 in the AutoTextSizeLabel tag
B4X:
Sub ResetUserFontScale(p As Panel)
    For Each v As B4XView In p.GetAllViewsRecursive
        If v Is Panel Then
            v.Color=xui.Color_Magenta
        Else if v Is Button Then
            Dim b As Button=v
            b.Color=xui.Color_Green
            b.Text="Click me"
            b.TextSize=40
        Else if v Is Label Then
            Dim lbl As Label = v           
            If lbl.Tag ="0" Then  'in designer put 0 in the regular label tag and 1 in the AutoTextSizeLabel tag
                lbl.Text= "I am just a label"
                lbl.Color=xui.Color_Yellow
                lbl.TextSize= 30
            Else if lbl.Tag ="1" Then
                lbl.Text= "I am AutoTextSizeLabel"
                lbl.Color=xui.Color_Blue
                lbl.TextSize=10
            End If
        End If
    Next
End Sub
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
And after you do everything then the user will not be able to read the text as it is too small for the user. The user chose to increase the text size for a reason.
As I said... the app is already made keeping in mind that is targeted to old people, so the texts and icons are already big.
If someone has the zoom option enabled it looks like an elephant in a drawer ?.

Apart for the joke.. actually in some cases the texts and icons became so big that them are cutted out.. so they are unreadable anyway. And making the default text smaller became problematic for the ones that does not have the zoom enabled maybe.
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
What about if you try to involve the Tag property. Something like this works, but I have not applied it to accessibility to see if it works. In designer put 0 in the regular label tag and 1 in the AutoTextSizeLabel tag
B4X:
Sub ResetUserFontScale(p As Panel)
    For Each v As B4XView In p.GetAllViewsRecursive
        If v Is Panel Then
            v.Color=xui.Color_Magenta
        Else if v Is Button Then
            Dim b As Button=v
            b.Color=xui.Color_Green
            b.Text="Click me"
            b.TextSize=40
        Else if v Is Label Then
            Dim lbl As Label = v          
            If lbl.Tag ="0" Then  'in designer put 0 in the regular label tag and 1 in the AutoTextSizeLabel tag
                lbl.Text= "I am just a label"
                lbl.Color=xui.Color_Yellow
                lbl.TextSize= 30
            Else if lbl.Tag ="1" Then
                lbl.Text= "I am AutoTextSizeLabel"
                lbl.Color=xui.Color_Blue
                lbl.TextSize=10
            End If
        End If
    Next
End Sub
Yeah, it could work, i will test it later. thanks for the suggestion
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
What about if you try to involve the Tag property. Something like this works, but I have not applied it to accessibility to see if it works. In designer put 0 in the regular label tag and 1 in the AutoTextSizeLabel tag
B4X:
Sub ResetUserFontScale(p As Panel)
    For Each v As B4XView In p.GetAllViewsRecursive
        If v Is Panel Then
            v.Color=xui.Color_Magenta
        Else if v Is Button Then
            Dim b As Button=v
            b.Color=xui.Color_Green
            b.Text="Click me"
            b.TextSize=40
        Else if v Is Label Then
            Dim lbl As Label = v         
            If lbl.Tag ="0" Then  'in designer put 0 in the regular label tag and 1 in the AutoTextSizeLabel tag
                lbl.Text= "I am just a label"
                lbl.Color=xui.Color_Yellow
                lbl.TextSize= 30
            Else if lbl.Tag ="1" Then
                lbl.Text= "I am AutoTextSizeLabel"
                lbl.Color=xui.Color_Blue
                lbl.TextSize=10
            End If
        End If
    Next
End Sub
Before trying this solution I checked if I was already using the .Tag property for something else.. and I was.
So in the end i modified the AutoTextSizeLabel class itself to add the "Ingore User Font Scale" property directly there.

This is the modified class
 
Upvote 0

Ertan

Active Member
Licensed User

B4X:
#if Java
import android.content.*;
import android.content.res.*;
@Override
protected void attachBaseContext(Context newBase) {
    super.attachBaseContext(newBase);
    final Configuration override = new Configuration(newBase.getResources().getConfiguration());
    override.fontScale = 0.9f;
    applyOverrideConfiguration(override);
   BA.Log("attachBaseContext");
}
#End If
Maybe this code can work for you. If you are using B4xpages, add it to the Main page.
 
Upvote 0
Top