Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodenameOne TextView Foreground Color

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?

like image 601
Guzzer Avatar asked Apr 10 '26 01:04

Guzzer


1 Answers

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.

like image 153
Shai Almog Avatar answered Apr 12 '26 13:04

Shai Almog