Android Question [Solve] SetColorAnimated with Corner Radius

Discussion in 'Android Questions' started by rraswisak, Jan 3, 2019.

  1. rraswisak

    rraswisak 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.

    Code:
    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
    Code:
    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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Use B4XView.SetColorAnimated. It looks and works better.

    Code:
    Sub Globals
       
    Private Label1 As B4XView
       
    Private xui As XUI
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
       
    Activity.LoadLayout("1")
    End Sub

    Sub Activity_Click
       Label1.SetColorAnimated(
    1000, xui.Color_Red, xui.Color_Blue)
    End Sub
     
  3. rraswisak

    rraswisak 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
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Have you tried it?
     
  5. rraswisak

    rraswisak 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:
    Code:
    Sub Label1_Click
       
    Dim col1, col2 As GradientDrawable
       
    Dim c1(2), c2(2As 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
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Your code is wrong. You should carefully follow the code I posted and understand how to use it.
     
  7. rraswisak

    rraswisak Member Licensed User

    ok, i have decide to use ColorDrawable instead of GradientDrawable

    this is final result:
    toggle.gif

    thank you for all your support
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice