【问题标题】:Blackberry Listfield highlight color黑莓 Listfield 高亮颜色
【发布时间】:2012-03-05 15:45:29
【问题描述】:

改变黑莓 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);

【问题讨论】:

  • 在此处添加您的 drawlistrow 代码
  • 我有 5 个不同的 LISTS,想添加一个通用代码来突出显示焦点我只在 drawlistrow 方法中呈现数据

标签: blackberry listfield


【解决方案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 代码,以便我们帮助您提高性能。

【讨论】:

  • 我需要更改焦点上显示的项目的默认蓝色
【解决方案2】:

为此屏幕创建一个booleanboolean _inFocus = false; 。在 Listfield 构造函数中添加两个方法(onfocus,onunfocus) .protected 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 中突出显示行的简单方法。 希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-18
    相关资源
    最近更新 更多