Android Question current color of the button

kyliejourney

New Member
I need to know the current color of the button, the color changes randomly, and I need to know its color, what procedures allow it? I ask you not to kick hard, if anything, I'm just a beginner :)
 

udg

Expert
Licensed User
Longtime User
Can't you simply take note of the new color when it changes? Randomly or not, you have an assignment statement there to make it happen, right?
It's at all possible that I missed you point, but the above looks somewhat logical so i posted it anyway.

BTW, why did you post yor question in this forum's section?
 
Last edited:
Upvote 0

kyliejourney

New Member
Can't you simply take note of the new color when it changes? Randomly or not, you have an assignment statement there to make it happen, right?
It's at all possible that I missed you point, but the above looks somehwta logical so i posted it anyway.

BTW, why did you post yor question in this forum's section?

yes, I think I can just use notes, but I thought that there are some special functions for this
thanks anyway!

I didn't know where to put it, so I chose the "General Forum", sorry. how can i move the question?
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Sorry, I didn't explain myself well.
When I said " Can't you simply take note " I referred to the possibility to store the newly assigned value in a global variable (or in the Tag property of the button) not to jot it down on paper after reading a log statement.
You could even store in Tag an history of last used colors, if you need it.

Moving thread: you can't. Eventually @Erel will do it.

ps: he already did it.. eheh
 
Upvote 0

kyliejourney

New Member
Sorry, I didn't explain myself well.
When I said " Can't you simply take note " I referred to the possibility to store the newly assigned value in a global variable (or in the Tag property of the button) not to jot it down on paper after reading a log statement.
You could even store in Tag an history of last used colors, if you need it.

Moving thread: you can't. Eventually @Erel will do it.

ps: he already did it.. eheh
I'll go figure it out, thanks for the answer! :)
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
I'll go figure it out, thanks for the answer! :)


Maybe this will shed some light on a possible solution ...
B4X:
Private MyTimer As Timer  'process global

Private xui As XUI
Private btnMyButton As B4XView
Private pnlMyPanel As B4XView

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("test")

    MyTimer.Initialize("MyTimer", 5000)
    MyTimer.Enabled = True
'.......................................................

Sub MyTimer_Tick
    Dim MyColor As Int  = xui.Color_ARGB(255,Rnd(1,255),Rnd(1,255),Rnd(1,255))
    btnMyButton.Color = MyColor
    btnMyButton.Tag = MyColor     '@@@ Store the current color in the Button.Tag property  ... OR store it in a Global Variable !
End Sub

Private Sub btnMyButton_Click  'recolor the panel , same as button
    pnlMyPanel.Color = btnMyButton.tag
End Sub



PS: if you are slightly confused with re XUI / B4XViews then just make the following changes ...
B4X:
Private btnMyButton As Button
Private pnlMyPanel As Panel

Sub MyTimer_Tick
Dim MyColor As Int   = Colors.ARGB(255,Rnd(1,255),Rnd(1,255),Rnd(1,255))
'...............  more
 
Last edited:
Upvote 0

mangojack

Expert
Licensed User
Longtime User
As a follow up ,should you need the Hex color value ...
B4X:
 Log(ColorToHex(MyColor))

Private Sub ColorToHex(clr As Int) As String
    Dim bc As ByteConverter
    Return bc.HexFromBytes(bc.IntsToBytes(Array As Int(clr)))
End Sub


 
Upvote 0
Top