Android Question How to adjust text in an EditText

vecino

Well-Known Member
Licensed User
Longtime User
Hi, is it possible to fit the text to the EditText size?
I would also be happy if the part that doesn't fit could be cut off, as long as what does fit is displayed correctly.

I've tried AutoTextSizeLabel (I can also use a Label) but I need to change the width on execution depending on certain user preferences. And AutoTextSizeLabel doesn't have a "Width" property.
Thanks.

ajustar.png
 

Mahares

Expert
Licensed User
Longtime User
is it possible to fit the text to the EditText size?
Did you by any chance take a look at this code snippet:
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Another one (same for Edittext's):

B4X:
Sub SetLabelTextSize(lbl As Label, txt As String, MaxFontSize As Float, MinFontSize As Float)
    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
End Sub
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Did you by any chance take a look at this code snippet:
Hello, it seems that this option is only valid for android 8+.
Anyway, I'll keep it in mind for later. For when my customers upgrade their devices.
Thank you.
 
Upvote 0
Top