07-13-2012 04:40 AM - edited 07-13-2012 04:53 AM
Hello,
I want to change the blue color of focus on items. I use this code to create items on screens.
VerticalFieldManager manager = (VerticalFieldManager) getMainManager();
gfm = new GridFieldManager(rows, columns, GridFieldManager.FIXED_SIZE);
manager.add(gfm);
int columnWidth = (Display.getWidth() / columns)
- gfm.getColumnPadding();
for ( i = 0; i < columns; i++) {
gfm.setColumnProperty(i, GridFieldManager.FIXED_SIZE, columnWidth);
}
BitmapField[] images = new BitmapField[6];
EncodedImage Icon = null;
for (i = 0; i < 6; i++) {
Icon = EncodedImage
.getEncodedImageResource("img/HOME.png");
images[i] = new BitmapField(Icon.getBitmap(), Field.FIELD_HCENTER
| Field.FIELD_VCENTER | Field.FOCUSABLE) {
protected void layout(int width, int height) {
setExtent(getPreferredWidth()+20, getPreferredHeight() + 15);
}
protected void paint(Graphics graphics) {
super.paint(graphics);
graphics.drawText("text", 0,
getBitmapHeight(), 2, getBitmapWidth() + 20);
}
};
gfm.setPadding(10, 0, 0, 0);
gfm.setRowPadding(20);
images[i].setPadding(20, 10, 5, 10);
gfm.add(images[i]);
}
}
Thanks
07-13-2012 04:43 AM
07-13-2012 05:41 AM
Soory about the format I edit my code
how can I use the method drawFocus in my code ??
07-13-2012 05:46 AM
07-13-2012 05:51 AM
I use this method but nothing happen
protected void drawFocus(Graphics graphics, boolean on) {
graphics.setBackgroundColor(Color.RED);
super.drawFocus(graphics, on);
}
07-13-2012 06:14 AM
I recommend that you review the JavaDoc.
07-13-2012 10:18 AM
Take a look at Field.setBackground method with two parameters: int visual, Background background. The visual parameter can be one of the VISUAL_STATE_... constants, also defined in Field class. Define the desired background for VISUAL_STATE_FOCUS (and VISUAL_STATE_NORMAL, if necessary). This way you won't even have to override drawFocus - the framework will take care of it for you.