黑莓 - 设置背景的LabelField色 [英] Blackberry - Setting LabelField background color
问题描述
我要放置几个LabelFields与一个MainScreen右对齐文本与爱丽丝蓝色背景。不幸的是,我似乎无法弄清楚如何做到这一点。
I want to place several LabelFields with right-aligned text on a MainScreen with an alice blue background. Unfortunately I can't seem to figure out how to make that happen.
我能做的就是把我的底色为Color.ALICEBLUE在屏幕上MainScreen和地点LabelFields最好的(也有爱丽丝蓝色背景)。
The best I can do is set my backround to Color.ALICEBLUE on a MainScreen and place LabelFields on the screen (also with a alice blue background).
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
对齐。
Overriding the MainScreen paint routine gives me my alice blue background, but overriding the LabelFields' paint routines does not seem to be adequate. The result is a white row, with a alice blue background behind the label text only. Adding USE_ALL_WIDTH
corrects the background issue, but I can't right align with USE_ALL_WIDTH
.
有谁知道围绕着工作呢?
Does anyone know a work around for this?
推荐答案
在版本< = 4.5,你可以用overrided油漆创建VerticalFieldManager():
In versions <= 4.5 you can create VerticalFieldManager with overrided paint():
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);
}
}
然后用它屏幕的youre添加简单的labelField属性它:
Then use it on youre screen adding simple LabelField to it:
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()为默认的屏幕管理方式:
In versions >= 4.6 you can use setBackgroud() method for default screen manager:
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));
}
}
请参阅BB KB DB-00131 - 如何 - 改变屏幕的背景颜色
这篇关于黑莓 - 设置背景的LabelField色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!