Android Question Changing background color of a Label by RGB values or Hex values

Toni

Member
Licensed User
Longtime User
I like to know how to change the background color of a B4xview by ARGB or RGB or Hex values, in my case RGB or hex values for a Label, please the easier way. Thank you!
 

DonManfred

Expert
Licensed User
Longtime User
B4X:
Label1.Color = Colors.RGB(48,48,48)
 
Upvote 0

Toni

Member
Licensed User
Longtime User
Next Questions in this context:
I like to have 14 different R, G and B values for 14 different states of my label. I learned the fastest way to use tables in b4x is to use maps. But each key is unique. But I like to have Keys like 1.R 1.G 1B, 2.R and so on. And i like to use the number of the key as a criterium for the state. Is there a short way to do so? Or another better solution? Thanks in advance!
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
You can declare a Type
B4X:
Type MyState (R as Int, G as Int, B as Int)
and then use it
B4X:
Dim State1 as MyState
State1.R = 50
State1.G = 50
State1.B = 50
Label1.Color = Color.RGB(State1.R, State1.G, State1.B)
For convenience you should create a Sub where you declare all the States so then they will be ready to use.
But you must declare even all States in Globals.
Instead of State1 you can use S1 to make it shorter if you like it.
 
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
If could be convenient to declare them as an Array
B4X:
Dim S(14) as MyState
S(0).R = 10
S(0).G = 10
S(0).B = 10
S(1).R = 20
S(1).G = 20
S(1).B = 20
........
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
How is the state defined ?
Do you really need 14 different R G B values, couldn't you define directly 14 colors ?
I would define the states as an Int with values from 0 to 13 and an array of colors.
B4X:
    Private State As Int
    Private StateColor(14) As Int
Define the 14 colors.
B4X:
    StateColor(0) = xui.Color_RGB(255, 0, 0)
    StateColor(1) = xui.Color_RGB(0, 255, 0)
    '
    StateColor(13) = xui.Color_RGB(10, 210, 20)
And depending on the state value set the color.
B4X:
    State = 10
    MyLabel.Color = StateColor(State)
 
Upvote 1

Toni

Member
Licensed User
Longtime User
It should be if I've got it anytime to an good end a version of '2048' game.

I've decided to write all 14 different RGB values in a row to an array.

I get the values like this:
Power from base 2, exeptional power=0
exp=Logarithm(label(any no).text,2)
label(any no).Color = Colors. RGB(RGBval(exp*3),RGBval(exp*3+1),RGBval(exp*3+2))

But thank you all for helping!
 
Upvote 0
Top