Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Colors CodenameOne文本视图前景色_Colors_Textfield_Codenameone - Fatal编程技术网

Colors CodenameOne文本视图前景色

Colors CodenameOne文本视图前景色,colors,textfield,codenameone,Colors,Textfield,Codenameone,我刚开始使用代码名one,并尝试设置TextView的前景(文本)颜色。将其设置为红色,并在按下按钮后写入文本。代码在button的action listener方法中执行: mValueField.getStyle().setFgColor(0xFF0000); // set red color mValueField.setText("Fill in!"); // write info text 将焦点设置到字段后,文本应消失,颜色应再次为黑色。代码在TextField的focusgoun

我刚开始使用代码名one,并尝试设置TextView的前景(文本)颜色。将其设置为红色,并在按下按钮后写入文本。代码在button的action listener方法中执行:

mValueField.getStyle().setFgColor(0xFF0000); // set red color
mValueField.setText("Fill in!"); // write info text
将焦点设置到字段后,文本应消失,颜色应再次为黑色。代码在TextField的focusgound()方法中执行:

问题是文本消失了,但新字符仍然是红色而不是黑色

有我的解决方案吗?

不要使用
getStyle()
它是为在
paint()
或类似方法中使用而设计的。由于组件有多个状态,您需要自定义每个单独的状态,例如
getUnselectedStyle()
getSelectedStyle()

或者您可以使用
getAllStyles()
通过一次调用来设置所有样式

mValueField.setText(""); // clear info text
mValueField.getStyle().setFgColor(0x000000); // set black color