Android Question Best way to do a ColorAnimated Loop?

JohnC

Expert
Licensed User
Longtime User
I want a label to smoothly change from one color to another in a loop.

Right now I am using code like this:

B4X:
Sub tmrRecord_Tick
    
    tmrRecord.Enabled = False

    If tmrRecord.Interval = 300 Then
        tmrRecord.Interval = 400
        lblRecording.SetTextColorAnimated(400,0xFFFF0000)
        
    Else
        tmrRecord.Interval = 300
        lblRecording.SetTextColorAnimated(300, Colors.ARGB(80,180,180,180))
    End If
    
    tmrRecord.Enabled = True
    
End Sub

But it seems like of clunky using a timer to determine when the animation finished.

Is there a better way?
 

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
What you think about this code?

B4X:
Sub DoColorAnimate
        lblRecording.SetTextColorAnimated(400,0xFFFF0000)
        Sleep(400)
        lblRecording.SetTextColorAnimated(300, Colors.ARGB(80,180,180,180))
        Sleep(300)
        DoSomeThing
End Sub

Sub DoSomeThing
    Log ("Done")
End Sub
 
Upvote 0

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
Sorry, I think that at first time I had not understood what you wanted to do.

Maybe something like this?

B4X:
Sub Record_Click
    Recording=True
    DoColorAnimate
End Sub

Sub Activity_Click
    Recording=False
End Sub

Sub DoColorAnimate
    Do While Recording=True
        lblRecording.SetTextColorAnimated(300,0xFFFF0000)
        Sleep(300)
        lblRecording.SetTextColorAnimated(400, Colors.ARGB(80,180,180,180))
        Sleep(400)
    Loop
End Sub
 
Last edited:
Upvote 0

JohnC

Expert
Licensed User
Longtime User
I will see if this will work. Thank you.
 
Upvote 0
Top