I'm new to codename one and try to set the foreground (text) color of a TextView. Setting it to red color and writing a text after pressing a button works. The code is executed in button's action listener method:
mValueField.getStyle().setFgColor(0xFF0000); // set red color
mValueField.setText("Fill in!"); // write info text
After setting focus into the field the text should disappear and color should be black again. The code is executed in TextField's focusGained() method:
mValueField.setText(""); // clear info text
mValueField.getStyle().setFgColor(0x000000); // set black color
Problem is that the text disappears but new chars are still red instead of black.
Any solutions for me?
Don't use getStyle() it's designed for use within paint() or similar methods. Since the component has multiple states you need to customize every individual state e.g. getUnselectedStyle(), getSelectedStyle() etc.
Or you can use the getAllStyles() to set them all with a single call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With