Android Question Label TextColor

stefanoa

Active Member
Licensed User
Longtime User
How can i change textcolor via code?
i tried for ex.
B4X:
notesLabel.TextColor = Colors.Red
but don't change anything...
any help?
 

stevel05

Expert
Licensed User
Longtime User
That should work, is the label defined in a layout or in code?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Unfortunately you don't give enough information.
Do you initialize the Label in the code, you shouldn't ?
What is the background color behind the Label, if it's red you wont see the text ?
Do you have some text in the Label ?
Could you post a small project showing the problem ?
 
Upvote 0

stefanoa

Active Member
Licensed User
Longtime User
The problem is that the color set in the layout does not change.
I have various labels in layout (via designer), then, in code i have, for each label, the declaration (Dim) and the text:
B4X:
Dim notesLabel As Label
notesLabel.text ="Title"

and i have to set forecolor (for ex. red) with:
B4X:
      notesLabel.TextColor = Colors.Red

but the color set in the layout does not change...
 
Upvote 0

strat

Active Member
Licensed User
Longtime User
If dim line in your sub, notesLabel may not be equal to the notesLabel you created in the designer. Try to move dim line in into the globals.
 
Upvote 0

stefanoa

Active Member
Licensed User
Longtime User
If dim line in your sub, notesLabel may not be equal to the notesLabel you created in the designer. Try to move dim line in into the globals.
Dim is already in the Globals...
and if i not declare variable in globals, i have this error when i try to use it:
Error description: Undeclared variable 'noteslabel' is used before it was assigned any value.
 
Upvote 0

stefanoa

Active Member
Licensed User
Longtime User
For EditText instead work correctly..
In this case, if I want to change the forecolor, I must necessarily remove the labels from layout and draw all the labels via code (without using the designer)?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
This should not be the case, can you zip and post your project? It will give someone a chance to see why it's not working, otherwise we are guessing.
 
Upvote 0

stefanoa

Active Member
Licensed User
Longtime User
ok after a few attempts I resolved with the normal procedure, as described in post#5
thanks to all
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I have set two views, a Label and an EditText view in the Designer with TextColor = Blue.
Then I changed their TextColor properties to Colors.Red in the code.
The color is changed on the screen but no change in the Designer, as expected.
 

Attachments

  • LabelTextColor.zip
    7.2 KB · Views: 165
Upvote 0

stefanoa

Active Member
Licensed User
Longtime User
I have set two views, a Label and an EditText view in the Designer with TextColor = Blue.
Then I changed their TextColor properties to Colors.Red in the code.
The color is changed on the screen but no change in the Designer, as expected.
ok.. thanks
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…