Android Question [B4X] XUI Views AnimatedCounter I can't change text color

Schakalaka

Active Member
Licensed User
Hello. I would like to chenge teh counter text color, the number color

I use
B4X:
 animatedcounter.mBase.TextColor = Colors.Black
but it return this error:
B4X:
Error occurred on line: 362 (Act_Home)
java.lang.RuntimeException: Type does not match (class anywheresoftware.b4a.BALayout)
    at anywheresoftware.b4a.objects.B4XViewWrapper.typeDoesNotMatch(B4XViewWrapper.java:388)
    at anywheresoftware.b4a.objects.B4XViewWrapper.asLabelWrapper(B4XViewWrapper.java:213)
    at anywheresoftware.b4a.objects.B4XViewWrapper.setTextColor(B4XViewWrapper.java:236)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
    at com.clickandclaimbitcoin.android.act_home._lythome(act_home.java:3199)
    at com.clickandclaimbitcoin.android.act_home._design(act_home.java:587)
    at com.clickandclaimbitcoin.android.act_home._activity_create(act_home.java:521)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at com.clickandclaimbitcoin.android.act_home.afterFirstLayout(act_home.java:105)
    at com.clickandclaimbitcoin.android.act_home.access$000(act_home.java:17)
    at com.clickandclaimbitcoin.android.act_home$WaitForLayout.run(act_home.java:83)
    at android.os.Handler.handleCallback(Handler.java:808)
    at android.os.Handler.dispatchMessage(Handler.java:101)
    at android.os.Looper.loop(Looper.java:166)
    at android.app.ActivityThread.main(ActivityThread.java:7529)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)

any solution?
 

Schakalaka

Active Member
Licensed User
yes, but i would like to do from code, because i use a global variable for manage all texts colors and change it in one hit
 
Upvote 0

Schakalaka

Active Member
Licensed User
mBase is a panel. You cannot change its text color.

It is currently not possible to change the numbers color programmatically. You can extract AnimatedCounter.bas from the b4xlib and modify it so it will be possible. It won't be too complicated.
Give it a different name.

hello,
after a bit of time I have do it.

I have add this to the top
B4X:
#DesignerProperty: key: TextColor, DisplayName: Text Color, FieldType: Color, DefaultValue: 0xFF000000, Description:Text Color.

and ask to chatgpt a help

B4X:
Public Sub ApplyTextColor(textColor As Int)
    Dim cvs As B4XCanvas
    Dim r As B4XRect
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, DigitWidth, DigitHeight * 10)
    cvs.Initialize(p)
    r = cvs.MeasureText("5", lblTemplate.Font)
    Dim BaseLine As Int = DigitHeight / 2 - r.Height / 2 - r.Top
    For i = 0 To 9
        cvs.DrawText(i, DigitWidth / 2, i * DigitHeight + BaseLine, lblTemplate.Font, textColor, "CENTER")
    Next
    cvs.Invalidate
    Dim res As B4XBitmap = cvs.CreateBitmap
    cvs.Release
    For Each iv As B4XView In ImageViews
        iv.SetBitmap(res)
    Next
End Sub

I have add the new file to the my xui library.
maybe this can be helpfull for others.
 
Upvote 0
Top