As erel rightly points out, this
is not a B4A bug, but a result of changes introduced by android 14.
So i have yet again to look into how to autozise labels fonts.
Googling a bit turns out that this should be the best (?) approach.
the setMaxLines method is needed for text that you want to be single line, otherwise two things are going to happen
1) Label is multiline, Autosize will occupy as most area as possible making text multiline if necessary
2) Label is singleline, Autosize will set for max height. If the width is too low the text will be cropped
If you setMaxLines to 1 (or to whatever lines you want to show) and the label is multiline, Autosize will do what expected: show a single line, text size set to max, adjusted for both width and height.
AutoSize produces the expected result at all font scales, effectively working around the issue described above.
I take suggestions to further enhance the code (for example, get rid of reflections?)
Android 14, Label.TextSize doesn't play well with font scaling
Since the update to Android 14 we had some customer complaining that our applications wouldn't launch. The condition to trigger this error is that the system font would be changed to be bigger than the default size. For my test i just set it at the biggest This was ultimately tracked down to a...
www.b4x.com
So i have yet again to look into how to autozise labels fonts.
Googling a bit turns out that this should be the best (?) approach.
B4X:
'Optional, but required if you NEED the text to be single line.
Dim r As Reflector
r.Target = lbl
r.RunMethod2("setMaxLines", 1, "java.lang.int") '1 Because single line, use actual number of lines instead
Dim jo As JavaObject
jo.InitializeStatic("android.support.v4.widget.TextViewCompat")
jo.RunMethod("setAutoSizeTextTypeUniformWithConfiguration", Array(lbl, 1, 300, 1, 1))
the setMaxLines method is needed for text that you want to be single line, otherwise two things are going to happen
1) Label is multiline, Autosize will occupy as most area as possible making text multiline if necessary
2) Label is singleline, Autosize will set for max height. If the width is too low the text will be cropped
If you setMaxLines to 1 (or to whatever lines you want to show) and the label is multiline, Autosize will do what expected: show a single line, text size set to max, adjusted for both width and height.
AutoSize produces the expected result at all font scales, effectively working around the issue described above.
I take suggestions to further enhance the code (for example, get rid of reflections?)