Android Question [Solved] B4XViews textsize in B4XPages

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All,

Below is a routine from a Sub to adjust the textsize for the device. I think the Sub was originally a snippet from Klaus.

The textsize Sub has been working well for a long time, I have tried to implement it in B4X pages with B4XViews and failed.

B4X:
'TextSizeScale is calculated by the first part of the sub'
    For Each v As View In Activity.GetAllViewsRecursive  'Adjust all textviews by TextSizeScale
        If v Is Label Then
            Private lbl As Label = v
            lbl.TextSize = lbl.TextSize * TextSizeScale
        End If
    Next

The following code is what I have tried without success with several variations. The App appears to be running somewhere but not in view. and nothing appears in the log.
The EditText part works if I noble the B4X part.

B4X:
    'Adjust text size for views by TextSizeScale which has been already calculated
    'Some views are on child panels of ActivityPnl

    For Each v As View In ActivityPnl.GetAllViewsRecursive
        If v Is EditText Then
            'Log("ET")
            Private ET1 As EditText = v
            ET1.TextSize = ET1.TextSize * TextSizeScale
        Else
            'Log(v.Tag)
            Private B4XV As B4XView = v      '.Tag                        'Could be Button, Label, Panel
            B4XV.TextSize = B4XV.TextSize * TextSizeScale   
        End If
    Next


Any help much appreciated.

Regards Roger
 

LucaMs

Expert
Licensed User
Longtime User
Not tested, wrote here directly.
B4X:
    For Each v As B4XView In ActivityPnl.GetAllViewsRecursive
        If v Is EditText Then
            v.TextSize = v.TextSize * TextSizeScale
        Else If v Is Label Then
            v.TextSize = v.TextSize * WhatYouWant1
        Else If v Is Button Then
            v.TextSize = v.TextSize * WhatYouWant2
        End If
    Next
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Use:

B4X:
'TextSizeScale is calculated by the first part of the sub'
    For Each v As B4XView In Root.GetAllViewsRecursive  'Adjust all textviews by TextSizeScale
        If v Is Label Then
            Private lbl As Label = v
            lbl.TextSize = lbl.TextSize * TextSizeScale
        End If
    Next
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
Thanks LucaMs, not quite, but close.
Thanks Klaus, beat me by a head.

This is the code I derived from LucaMs post and then Klaus posted much the same. Thanks Klaus.

B4X:
For Each v As View In ActivityPnl.GetAllViewsRecursive
        If v Is Label Then
            Private B4XV As Label = v
            B4XV.TextSize = B4XV.TextSize * TextSizeScale
        End If
    Next

This adjusts the textsize for Labels, Buttons and EditTexts. [Buttons and Edts just being fancy labels]

Many thanks gentlemen.
Regards Roger


Roger
Not tested, wrote here directly.
B4X:
    For Each v As B4XView In ActivityPnl.GetAllViewsRecursive
        If v Is EditText Then
            v.TextSize = v.TextSize * TextSizeScale
        Else If v Is Label Then
            v.TextSize = v.TextSize * WhatYouWant1
        Else If v Is Button Then
            v.TextSize = v.TextSize * WhatYouWant2
        End If
    Next
 
Upvote 0
Top