Android Question How to set label TextColor back to default by code?

alain bertrand

Member
Licensed User
Longtime User
A label color is defined as Default in the designer.
The code turns it into (e.g.) Label.TextColor = Colors.red.
How to bring the color back to Default by code without selecting any other color?
Thanks in advance.
 

Mahares

Expert
Licensed User
Longtime User
How to bring the color back to Default by code without selecting any other color?
B4X:
lbl1.Tag=lbl1.Background  'initially set to default , stored color in tag
   
    lbl1.Color=Colors.Red    'then later play around with colors
       
    lbl1.Background=lbl1.Tag  'when you want to go back to default setting issue this code
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Maybe something like this if you are dealing with the label text colors instead of the label color:
B4X:
lbl1.Text="You are ready"
    lbl1.Tag=lbl1.TextColor
    lbl1.TextColor=Colors.Magenta   
    lbl1.textColor=lbl1.Tag
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Maybe something like this if you are dealing with the label text colors instead of the label color:
B4X:
lbl1.Text="You are ready"
    lbl1.Tag=lbl1.TextColor
    lbl1.TextColor=Colors.Magenta  
    lbl1.textColor=lbl1.Tag
In addition, the tag property can be used to store an array, a list or even a map, so you can use it to store any "default" values you want
 
Upvote 0
Top