Android Question Large Text

aaronk

Well-Known Member
Licensed User
Longtime User
Hi,

I am trying to work out how to scale the text size in my layout based on the device if it has 'Large Text' enabled in the Android settings?

I have been watching Erels video tutorial on the scaling but can't work out how to do this.

I am testing this using my Nexus 5.

For testing I created a small sample on what I am trying to do..

In the image below, the screenshot on the left is with 'Large Text' turned off (default) which is what I want. If I enable 'Large text' from the Android accessibility settings, then it shows the text larger but I want it to auto scale down to the normal text size like on the left screenshot. (In other words, I want it to look like the screenshot on the left regardless what text size the user has set on the Android system)

I have my layout variant set to 320 x 480, scale= 1 (160 dpi)
In the designer script I only have AutoScaleAll.
In the designer, I only have a label.

Is there a way for my app to ignore if the user has 'large text' enabled and scale it to default and not large text ?

screenshot.png
 

udg

Expert
Licensed User
Longtime User
I did a very quick search and found a reference to Configuration.fontScale.
Maybe you could read that value and apply a reduction scale factor to current text size.
 
Upvote 0

aaronk

Well-Known Member
Licensed User
Longtime User
I ended up using:

B4X:
For Each v As View In Activity.GetAllViewsRecursive
        If v Is Label Then
            Dim c As Label
            c = v
            c.TextSize = c.TextSize / Starter.access.GetUserFontScale
        End If
    Next

Which works fine if the label is in the activity.

But can't work out how to do the same if the label is in a TabStrip, as it doesn't look like it's changing any label text sizes in the TabStrip ?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Change the code to:
B4X:
Sub RescaleTextSize(parent As Panel)
For Each v As View In parent.GetAllViewsRecursive
        If v Is Label Then
            Dim c As Label
            c = v
            c.TextSize = c.TextSize / Starter.access.GetUserFontScale
        End If
    Next
End Sub
Add a base panel for each of the TabStrip tabs.
B4X:
For Each Parent As Panel In Array(Activity, BasePanel1, BasePanel2, ...)
 RescaleTextSize(Parent)
Next
 
Upvote 0
Top