Search code examples
blackberryjava-mehighlightingonfocus

How to change the highlighter(blue) in a blackberry application?


The default highlight color in blackberry is blue. I'm currently doing an application which dominant color is red. Is there a way to change the highlighter color to red? I googled it and find a solution for the ListField, how about for other fields like buttons, textFields, bitmapFields etc...?


Solution

  • Found this implementation in the blackberry forum, have tried it and it works perfectly. But you need to override this method for each fields that you want to have a different highlighter.

    protected void drawFocus( Graphics g, boolean on ) {    
        XYRect focusRect = new XYRect();                
        getFocusRect( focusRect );                
        int yOffset = 0;                
    
        if ( isSelecting() )     
        {        
            yOffset = focusRect.height >> 1;        
            focusRect.height = yOffset;        
            focusRect.y += yOffset;    
        }                
        g.pushRegion( focusRect.x, focusRect.y, 
                      focusRect.width, focusRect.height, 
                      -focusRect.x, -focusRect.y );   
        g.setBackgroundColor(/*your color here*/);    
        g.setColor( 0xFFFFFF );    
        g.clear();                
        this.paint( g );                
        g.popContext();
    }