1

I am not able to set the focus on the HorizontalFieldManager having two LabelFields. I want to highlight the HorizontalFieldManager when it gets focus. I am using the following code, but it is not working.

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);

Here is the LabelField implementation.

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);
    }
};
4

3 回答 3

1

getFocusRect()功能可能会给您答案。它给出了在 Manager 中应用焦点的程度,然后可以使用Graphics.paint()方法或类。Border

于 2012-06-11T11:57:40.027 回答
0

如果您想关注您的标签字段,请使用final LabelField a= new LabelField("".FOCUSABLE).

于 2012-06-11T11:37:12.327 回答
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(...)- 这些方法只是为了刷新绘图而被覆盖。

于 2012-06-11T11:56:44.780 回答