Android Question [SOLVED] - Label - Border Color Animation

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hello

I was wondering if there was a similar method to label.SetTextColorAnimated(duration,ToColor) for changing the border color,
SetBorderColorAnimated(duration,ToColor)

Regards

John.
 

walterf25

Expert
Licensed User
Longtime User
Hello

I was wondering if there was a similar method to label.SetTextColorAnimated(duration,ToColor) for changing the border color,
SetBorderColorAnimated(duration,ToColor)

Regards

John.
This works for me

setBorderColorAnimated:
Sub SetBorderColorAnimated(lblview As Label, duration As Long, toColor As Int)
    Dim jo As JavaObject = lblview

    ' Create a Drawable with a border
    Dim initialColor As Int = xui.Color_Transparent ' Default starting color
  
    borderDrawable.InitializeNewInstance("android.graphics.drawable.GradientDrawable", Null)
    borderDrawable.RunMethod("setShape", Array(0)) ' 0 = RECTANGLE
    borderDrawable.RunMethod("setStroke", Array(5dip, initialColor)) ' 5dip border width, initial color
    jo.RunMethod("setBackground", Array(borderDrawable))

    ' Use JavaObject to call the static ValueAnimator.ofArgb method
    Dim clrs(2) As Int
    clrs(0) = initialColor
    clrs(1) = toColor
    Dim animator As JavaObject
    animator.InitializeStatic("android.animation.ValueAnimator")
    animator = animator.RunMethod("ofArgb", Array As Object(clrs))
    animator.RunMethod("setDuration", Array As Object(duration))

    ' Use CreateEvent to define the AnimatorUpdateListener
    ' Pass the `borderDrawable` JavaObject directly as the "Tag"
    Dim wrapper As JavaObject
    wrapper = animator.CreateEvent("android.animation.ValueAnimator.AnimatorUpdateListener", "AnimationUpdate", borderDrawable)
    animator.RunMethod("addUpdateListener", Array(wrapper))

    ' Start the animation
    animator.RunMethod("start", Null)
End Sub

' Handle the animation update in the Sub below
Sub AnimationUpdate_Event (Tag As Object, Args() As Object) As Object
    Dim valueAnimator As JavaObject = Args(0) ' Get the ValueAnimator object
    Dim animValue As Int = valueAnimator.RunMethod("getAnimatedValue", Null) ' Extract the animated value

    ' Update the border color
    borderDrawable.RunMethod("setStroke", Array(5dip, animValue))
End Sub

Just call the function like so
B4X:
SetBorderColorAnimated(lbl, 2000, xui.Color_Red)

Cheers
Walter
 

Attachments

  • labelcoloranimated (1).gif
    labelcoloranimated (1).gif
    94.6 KB · Views: 64
Last edited:
Upvote 0

Mehrzad238

Member
@walterf25 this looks nice and I like to use it.

Can I have a suggestion for this? Can you complete it and put it in an example part of the forum? I am pretty sure many of the users will appreciate your work.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
@walterf25 this looks nice and I like to use it.

Can I have a suggestion for this? Can you complete it and put it in an example part of the forum? I am pretty sure many of the users will appreciate your work.
I think is very simple to use, just create a project, add a label either in the designer or by code, pass that label to the function provided and it should work.
 
Upvote 0
Top