Hi, with labels I do it with the following code and it works very well.
Now I need to do the same for some buttons.
How can I do it?
Thank you.
B4X:
Sub SetLabelTextSize(lbl As Label, txt As String, MaxFontSize As Float, MinFontSize As Float) As ResumableSub
Dim FontSize = MaxFontSize As Float
Dim Height As Int
Dim stu As StringUtils
'
lbl.TextSize = FontSize
Height = stu.MeasureMultilineTextHeight(lbl, txt)
Do While Height > lbl.Height And FontSize > MinFontSize
FontSize = FontSize - 1
lbl.TextSize = FontSize
Height = stu.MeasureMultilineTextHeight(lbl, txt)
Loop
'
Return FontSize
End Sub
Try this.
This code automatically adjusts the view text size to fit.
B4A:
#AdditionalJar: com.android.support:support-compat
Sub SetAutoSizeBasedOnText(v As View)
Dim jo As JavaObject
jo.InitializeStatic("android.support.v4.widget.TextViewCompat")
jo.RunMethod("setAutoSizeTextTypeWithDefaults", Array(v, 1))
End Sub
Try this.
This code automatically adjusts the view text size to fit.
B4A:
#AdditionalJar: com.android.support:support-compat
Sub SetAutoSizeBasedOnText(v As View)
Dim jo As JavaObject
jo.InitializeStatic("android.support.v4.widget.TextViewCompat")
jo.RunMethod("setAutoSizeTextTypeWithDefaults", Array(v, 1))
End Sub