2012-03-05 152 views
0

什麼是改變黑莓ListField的亮點(焦點)顏色的最好方式,我已經使用了DRAWFOCUS方法確實亮點的東西,但它在去與黑莓Listfield高亮顏色

代碼性能太慢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); 
+0

添加drawlistrow代碼在這裏 – rfsk2010 2012-03-05 15:49:38

+0

我有5個不同的清單,並希望增加對焦點的通用代碼高亮我只在drawlistrow方法 – 2012-03-05 15:53:14

回答

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代碼,以便設置列表欄高亮顏色,我們可以幫助你提高個表現。

+0

渲染數據我需要改變對焦點 – 2012-03-05 16:02:20

+0

有沒有出現一個項目的默認藍色你試試我的代碼? – rfsk2010 2012-03-05 16:06:21

+0

試過這個成功! – Lucas 2014-01-14 16:49:58

0

爲此屏幕創建一個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中突出顯示行的簡單方法。 我希望它能幫助你。