Android Question [Solve] SetColorAnimated with Corner Radius

rraswisak

Active Member
Licensed User
Hi all,

I have a label with corner radius set to 20, then i want to change the color with SetColorAnimated method, the color was change but the corner radius is missing.

B4X:
Sub Label1_Click
     Dim Col1, Col2 As Int
     Col1 = Colors.Red
     Col2 = Colors.Green

     Label1.SetColorAnimated(500, Col1, Col2)
End Sub

If i define Col1 and Col2 as ColorDrawable, it raise error
B4X:
Sub Label1_Click
     Dim col1, col2 As ColorDrawable
     col1.Initialize(Colors.ARGB(175,255,0,0),20dip)
     col2.Initialize(Colors.ARGB(175,0,255,0),20dip)
     Label1.SetColorAnimated(500, Col1, Col2)
End Sub

thank you
 

rraswisak

Active Member
Licensed User
Thank you erel, but i think SetColorAnimated will remove corner radius previously set in designer.

So every time color has change, the corner radius will gone

Without Animated, i can change the color with ColorDrawable, in this case i want to use SetColorAnimated
 
Upvote 0

rraswisak

Active Member
Licensed User
Yes its work, but sorry i miss one information, in designer, i set label drawable to GradientDrawable.

try to figure it out with this code, but still get error:
B4X:
Sub Label1_Click
   Dim col1, col2 As GradientDrawable
   Dim c1(2), c2(2) As Int
   c1(0) = xui.Color_Blue
   c1(1) = xui.Color_White
   col1.Initialize("TOP_BOTTOM",c1)
   col1.CornerRadius = 20
   
   c2(0) = xui.Color_Red
   c2(1) = xui.Color_White
   col2.Initialize("TOP_BOTTOM",c2)
   col2.CornerRadius = 20
   
   If posLeft Then
       Label1.SetColorAnimated(500,col1, col2)
   Else
       Label1.SetColorAnimated(500,col2, col1)
   End If
   posLeft = Not(posLeft)
End Sub

 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…