【问题标题】:Set focus color on clickable array of HorizontalFieldManager in BlackBerry在 BlackBerry 中的水平字段管理器的可单击数组上设置焦点颜色
【发布时间】:2013-03-06 22:11:19
【问题描述】:

我有一个水平字段数组,每个字段都包含一个位图和一个标签字段。到目前为止,整行应该是可点击的,但是如何正确设置焦点颜色?目前 onFocus 和 onUnfocus 函数被完全忽略。

这是我的数组的定义:

for (int i = 0; i < listSize; i++) {
        logInDetailManager[i] = new HorizontalFieldManager(
                Manager.USE_ALL_WIDTH | Field.FOCUSABLE) {

            protected void onFocus(int direction) {
                super.onFocus(direction);
                background_color = Color.RED;
                invalidate();
            }

            protected void onUnfocus() {
                invalidate();
                background_color = Color.GREEN;
            }

这就是我添加水平字段的方式:

logInDetailManager[i].setChangeListener(this);
logInDetailManager[i].add(dummyIcon[i]);
logInDetailManager[i].add(new LabelField("hello"));
logInDetailManager[i].add(new NullField(Field.FOCUSABLE));
add(logInDetailManager[i]);

【问题讨论】:

  • 请在下方添加您的解决方案作为答案,而不是上方的问题区域。然后,您可以接受您自己的答案,让我们知道问题已解决。你也会得到一些分数。谢谢。

标签: arrays blackberry onfocus horizontalfieldmanager


【解决方案1】:

抱歉,我昨天无法对自己的帖子发表评论,因为我是 Stackoverflow 的新手;) 以下是我的解决方法:

我从 HFM 中删除了 onFocus() 和 onUnfocus() 并在 paint 方法中设置了背景颜色,以便在聚焦时更改整行颜色:

 protected void paint(Graphics graphics) {

        graphics.setBackgroundColor(isFocus() ? Color.RED : Color.GREEN);
        graphics.clear();
        invalidate();
        super.paint(graphics);
}

我还发现如果你想设置更复杂的背景(即带有渐变)你也可以使用 setBackground(int visual, Background background) 方法:

 Background bg_focus = (BackgroundFactory
        .createLinearGradientBackground(Color.GREEN, Color.LIGHTGREEN,
        Color.LIGHTGREEN, Color.GREEN));

 loginDetailManager[i].setBackground(VISUAL_STATE_FOCUS, bg_focus);

当使用这样的 setBackground 函数时,一定要删除你的paint方法!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-10
    • 1970-01-01
    • 1970-01-01
    • 2011-07-19
    • 1970-01-01
    • 1970-01-01
    • 2010-12-23
    相关资源
    最近更新 更多