黑莓 - 设置 LabelField 背景颜色
-
12-09-2019 - |
题
我想在具有爱丽丝蓝色背景的主屏幕上放置几个带有右对齐文本的标签字段。不幸的是,我似乎不知道如何实现这一点。
我能做的最好的事情就是在主屏幕上将背景设置为 Color.ALICEBLUE 并将 LabelFields 放在屏幕上(也具有爱丽丝蓝色背景)。
public void paint(Graphics graphics) {
graphics.setBackgroundColor(Color.ALICEBLUE);
graphics.clear();
super.paint(graphics);
}
和...
LabelField display = new LabelField("", LabelField.FIELD_RIGHT){
public void paint(Graphics graphics) {
graphics.setColor(Color.DIMGRAY);
graphics.setBackgroundColor(Color.ALICEBLUE);
graphics.clear();
super.paint(graphics);
}
};
覆盖 MainScreen 绘制例程给了我爱丽丝蓝色背景,但覆盖 LabelFields 的绘制例程似乎还不够。结果是白色行,仅在标签文本后面带有爱丽丝蓝色背景。添加 USE_ALL_WIDTH
纠正了背景问题,但我无法正确对齐 USE_ALL_WIDTH
.
有谁知道解决这个问题的方法吗?
解决方案
在<= 4.5版本中,您可以使用覆盖的paint()创建VerticalFieldManager:
class BGManager extends VerticalFieldManager {
public BGManager() {
super(USE_ALL_HEIGHT|USE_ALL_WIDTH);
}
public void paint(Graphics graphics)
{
graphics.setBackgroundColor(Color.DARKRED);
graphics.clear();
super.paint(graphics);
}
}
然后在屏幕上使用它,向其中添加简单的 LabelField:
class Scr extends MainScreen {
BGManager manager = new BGManager();
public Scr() {
super();
add(manager);
manager.add(new LabelField("Hello!", FIELD_RIGHT));
manager.add(new LabelField("This is a test", FIELD_RIGHT));
}
}
在版本 >= 4.6 中,您可以使用 setBackgroud() 方法作为默认屏幕管理器:
class Scr extends MainScreen {
public Scr() {
super();
VerticalFieldManager manager =
(VerticalFieldManager)getMainManager();
manager.setBackground(
BackgroundFactory.createSolidBackground(
Color.DARKRED));
manager.add(new LabelField("Hello!", FIELD_RIGHT));
manager.add(new LabelField("This is a test", FIELD_RIGHT));
}
}
其他提示
使用
new LabelField("",LabelField.USE_ALL_WIDTH | DrawStyle.RIGHT);
,而不重写的的LabelField漆方法。
不隶属于 StackOverflow