我无法将注意力集中在HorizontalFieldManager
有两个LabelFields
上。我想突出显示HorizontalFieldManager
何时获得焦点。我使用以下代码,但它无法正常工作。
HorizontalFieldManager hrzMgrTimeLabel = new HorizontalFieldManager(
Manager.USE_ALL_HEIGHT|Manager.FOCUSABLE) {
protected void onFocus(int direction) {
focussed = true;
invalidate();
super.onFocus(direction);
}
protected void onUnfocus() {
focussed = false;
invalidate();
super.onUnfocus();
}
protected void paint(Graphics g) {
g.setBackgroundColor(0x646060);
if (focussed) {
g.setColor(Color.BLUE);
}
g.clear();
super.paint(g);
}
};
hrzMgrTimeLabel.add(a);
hrzMgrTimeLabel.add(b);
horizontalFieldManager_left15.add(hrzMgrTimeLabel);
这是LabelField实现。
final LabelField a= new LabelField("") {
protected void paint(Graphics graphics) {
graphics.setColor(Color.WHITE);
graphics.setBackgroundColor(0x646060);
graphics.clear();
super.paint(graphics);
}
};
final LabelField b= new LabelField("") {
protected void paint(Graphics graphics) {
graphics.setColor(Color.WHITE);
graphics.setBackgroundColor(0x646060);
graphics.clear();
super.paint(graphics);
}
};
答案 0 :(得分:1)
getFocusRect()
功能可能会给你答案。
它给出了在Manager中应用焦点的程度,然后可以使用Graphics.paint()
方法或Border
类。
答案 1 :(得分:0)
如果您想要关注标签字段,请使用final LabelField a= new LabelField("".FOCUSABLE)
。
答案 2 :(得分:0)
HorizontalFieldManager
上至少需要一个可聚焦字段。以下行将做到这一点。
hrzMgrTimeLabel.add(new NullField(NullField.FOCUSABLE));
检查以下代码。
HorizontalFieldManager hrzMgrTimeLabel = new HorizontalFieldManager(Manager.USE_ALL_HEIGHT | Manager.FOCUSABLE) {
protected void paint(Graphics g) {
g.setBackgroundColor(isFocus() ? Color.BLUE : 0x646060);
g.clear();
super.paint(g);
}
protected void onFocus(int direction) {
invalidate();
super.onFocus(direction);
}
protected void onUnfocus() {
invalidate();
super.onUnfocus();
}
protected boolean navigationMovement(int dx, int dy, int status, int time) {
invalidate();
return super.navigationMovement(dx, dy, status, time);
}
protected boolean navigationClick(int status, int time) {
invalidate();
return super.navigationClick(status, time);
}
protected boolean navigationUnclick(int status, int time) {
invalidate();
return super.navigationUnclick(status, time);
}
};
final LabelField a = new LabelField("First Label Field") {
protected void paint(Graphics graphics) {
graphics.setColor(Color.WHITE);
super.paint(graphics);
}
};
final LabelField b = new LabelField("Second Label Field") {
protected void paint(Graphics graphics) {
graphics.setColor(Color.WHITE);
super.paint(graphics);
}
};
hrzMgrTimeLabel.add(new NullField(NullField.FOCUSABLE));
hrzMgrTimeLabel.add(a);
hrzMgrTimeLabel.add(b);
注意强> 的
onFocus(...)
,onUnfocus()
,navigationMovement(...)
,navigationClick(...)
,navigationUnclick(...)
- 这些方法仅用于刷新图纸。