0

更改黑莓 ListField 的突出显示(焦点)颜色的最佳方法是什么,我使用了 drawFocus 方法,它确实突出显示了一些东西,但它的性能太慢了,无法继续

drawlistrow 中的代码

Item item = (Item)this.listData.elementAt(this.getSelectedIndex());

    g.drawText (item.getItemNumber(), 2, y, Graphics.LEFT,20);
    g.drawText (item.getDescription(), 25, y, Graphics.LEFT,30);
    g.drawText (item.getItemType(), 60, y, Graphics.LEFT,15);

    g.setColor(0xC4C3C4);
    g.drawLine(2, y, 2, 115);
4

2 回答 2

1

您可以使用以下代码设置列表字段突出显示颜色

if (g.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS)) {
    //change focus color
        g.setBackgroundColor(MyColors.LIGHT_GRAY);  
        g.clear();
    //draw text
        g.setFont(boldTextFont);
        g.setColor(MyColors.White);
        g.drawText(text, 12, y);
    }

请添加您的 drawlistrow 代码,以便我们帮助您提高性能。

于 2012-03-05T15:53:41.477 回答
0

boolean为此屏幕创建一个。boolean _inFocus = false;. 比在构造函数中添加两个方法(onfocus,onunfocus)Listfieldprotected void onFocus(int direction) { _inFocus = true; super.onFocus(direction); } protected void onUnfocus() { _inFocus = false; super.onUnfocus(); }.

比在您的方法中写下以下drawListRow方法。在下面的方法中,我们将检查该行是否可聚焦。

if(_inFocus)
        {
            if(listField.getSelectedIndex() == index)
            {
                g.setGlobalAlpha(100);
                g.setColor(0xff9600);
                g.fillRect(0,y,getWidth(),getHeight());
                //invalidate();
            }
        }

这是在 中突出显示行的简单方法Listfield。我希望它会帮助你。

于 2012-03-07T04:39:34.863 回答