Android Question Change Label TextColor by variable

Marco Maria Vilucchi

Active Member
Licensed User
Longtime User
Hi, i need to change TextXolor of a Label and i can take the color from a variable
B4X:
    Dim ColActive As ColorDrawable
    Dim ColInactive As ColorDrawable
    ColActive.Initialize(Colors.black, 10dip)
    ColInactive.Initialize(Colors.LightGray, 10dip)
    Label1.textcolor=ColActive
    Label2.textcolor=ColInactive
    Label3.textcolor=ColInactive
    .....
    Label99.textcolor=ColInactive
    Label100.textcolor=ColActive
I have an errore on Label1.textcolor=ColActive and Label2.textcolor=ColInactive
Someone can help me?
Marco
 

Mahares

Expert
Licensed User
Longtime User
ColorDrawable is for background. You need to use something like this:
B4X:
Dim colActive As Int =Colors.Black
Dim colInactive As Int =Colors.LightGray
Label1.textcolor=ColActive
 Label2.textcolor=ColInactive
 Label3.textcolor=ColInactive
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Or even define as a Constant
B4X:
Private Const colActive As Int = Colors.Black
Private Const colInactive As Int = Colors.LightGray

'you can also define more colors than the built in Colors   
Private Const colActive As Int = Colors.RGB (0,139,139)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Another option. Right click, select Color Picker, choose the color and click on Copy to clipboard:

SS-2016-03-29_08.09.43.png

B4X:
Dim tc As Int = 0xFF800080 'the format is AARRGGBB
...
Label1.TextColor = tc
 
Upvote 0
Top