Hi,
I am new to B4A coding. I am using AutoTextSizeLabel class module to automatically set the font.
However, I noticed that I cannot change the color of the label through coding; only through designer.
For example, if I define label1 as AutoTextSizeLabel
and calling label1 gives only text with no textcolor option.
Anyone can guide me how to change the color through code?
Here is a copy of the AutoSizeTextLabel class I am using
I am new to B4A coding. I am using AutoTextSizeLabel class module to automatically set the font.
However, I noticed that I cannot change the color of the label through coding; only through designer.
For example, if I define label1 as AutoTextSizeLabel
and calling label1 gives only text with no textcolor option.
Anyone can guide me how to change the color through code?
Here is a copy of the AutoSizeTextLabel class I am using
B4X:
'Class module
Sub Class_Globals
Private cvs As Canvas
Private mLbl As Label
Private su As StringUtils
End Sub
Public Sub Initialize (Target As Object, EventName As String)
End Sub
Public Sub DesignerCreateView(Base As Panel, lbl As Label, props As Map)
Dim bmp As Bitmap
bmp.InitializeMutable(1,1) 'ignore
cvs.Initialize2(bmp)
Base.AddView(lbl, 0, 0, Base.Width, Base.Height)
mLbl = lbl
Dim r As Reflector
r.Target = mLbl
r.RunMethod4("setPadding", Array As Object(0,0,0,0), Array As String("java.lang.int", "java.lang.int", "java.lang.int", "java.lang.int"))
r.RunMethod4("setIncludeFontPadding", Array As Object(False), Array As String("java.lang.boolean"))
setText(mLbl.Text)
End Sub
Public Sub setText(value As String)
mLbl.Text = value
Dim multipleLines As Boolean = mLbl.Text.Contains(CRLF)
Dim size As Float
For size = 2 To 90
If CheckSize(size, multipleLines) Then Exit
Next
size = size - 0.5
If CheckSize(size, multipleLines) Then size = size - 0.5
mLbl.TextSize = size
End Sub
'returns true if the size is too large
Private Sub CheckSize(size As Float, MultipleLines As Boolean) As Boolean
mLbl.TextSize = size
If MultipleLines Then
Return su.MeasureMultilineTextHeight(mLbl, mLbl.Text) > mLbl.Height
Else
Return cvs.MeasureStringWidth(mLbl.Text, mLbl.Typeface, size) > mLbl.Width Or _
su.MeasureMultilineTextHeight(mLbl, mLbl.Text) > mLbl.Height
End If
End Sub
Public Sub getText As String
Return mLbl.Text
End Sub