Gradients

Bill Norris

Active Member
Licensed User
Longtime User
I am using the following to call sub in a Gradients code module

B4X:
Sub flash_next_button_tick

   Select btn_find_wines.tag
   Case "BT"
      btn_find_wines.Background=gradients.StateListDrawable(Main.theme_color_light, Main.theme_color_dark,Main.theme_color_dark, Main.theme_color_light, 5dip, "TOP_BOTTOM", "TOP_BOTTOM")
      btn_find_wines.Tag="TB"
   Case "TB"
      btn_find_wines.Background=gradients.StateListDrawable(Main.theme_color_light, Main.theme_color_dark,Main.theme_color_dark, Main.theme_color_light, 5dip, "BOTTOM_TOP", "BOTTOM_TOP")
      btn_find_wines.Tag="BT"
   End Select
End Sub

The above code is executed on a timer tick every 1/2 second. What this does is alternate the gradient style (TOP/BOTTOM, then BOTTOM/TOP) to create somewhat of a flashing affect to call attention to the button. It may be my imagination but it seems that this constant calling to the gradient sub is using up resources.
Is there a way to save those two gradient styles to a variable that I can refer to each tick rather than executing the code each time?
 

klaus

Expert
Licensed User
Longtime User
Yes you can define variables as StateListDrawable.
B4X:
Dim sdw1, sdw2 As StateListDrawable
.
.
sdw1 = gradients.StateListDrawable(Main.theme_color_light, Main.theme_color_dark,Main.theme_color_dark, Main.theme_color_light, 5dip, "TOP_BOTTOM", "TOP_BOTTOM")
sdw2 = gradients.StateListDrawable(Main.theme_color_light,  Main.theme_color_dark,Main.theme_color_dark, Main.theme_color_light,  5dip, "BOTTOM_TOP", "BOTTOM_TOP")
.
' etc
So you call the routine only one time for each and use the variables in the Tick routine.

Best regards.
 
Upvote 0
Top