Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 113
Registered: ‎09-30-2009
My Device: Bold 9700

Do you really need to draw your own buttons just to change background/focus color?

[ Edited ]

Hi

 

I have been struggling with buttons.  I would simply like to change the background focus color of the button from the default blue to red.  There seem to be many posts on this, but none with a clear/working example (other than creating your own button field by extending Field).  Is it really necessary to make an entire field type just to have the background color change on focus? I am refering to posts like this.

 

So far I have only been able to get the background around the text to change color when the button has focus.  Here is what I have so far (drawFocus w/ drawHighlightRegion does not seem to have an effect):

 

 

//Red background button
public class redButtonField extends ButtonField {
int myRed = 0x00d32b1b;
int _bgColor = Color.GRAY;
public redButtonField(String text, long setStyle) {
super(text, setStyle);
}


protected void paint(Graphics graphics) {
graphics.setBackgroundColor(_bgColor);
graphics.clear();
super.paint(graphics);
//graphics.drawText(this.getLabel(), 0, 0);
}

protected void onFocus (int direction) {
_bgColor = myRed;
invalidate();
super.onFocus(direction);
}

protected void onUnfocus() {
_bgColor = Color.GRAY;
invalidate();
super.onUnfocus();
}

public void drawFocus(Graphics graphics, boolean on) {
drawHighlightRegion(graphics, HIGHLIGHT_FOCUS | HIGHLIGHT_SELECT, true, 40, 0, getWidth(), getHeight());
super.drawFocus(graphics, on);
}
} //redButtonField