arrow_backward Back to blog

Blackberry Tip: Change the default focus highlight color of ListField

In Blackberry Java application development, every row in ListField has the default blue focus highlight color. There is no simple setter to change it. One way to change it is to overwrite the 'drawFocus' method. I'm going to walk you through the steps to change that.

Suppose we have a list to display each news feed from an RSS; we need to customize the row so that it looks like this:

In the non-focus state, the title of the news feed is in black, the date info is in gray, and the background color for the row is white. For the focus state the colors will be changed: the row gets a red highlight color and the title/date fields will get white. Here is the code:

The idea is to draw the customized highlight color and then draw the selected row again. The drawListRow method will draw each row; suppose we have the title field’s paint method like this:

Here the title takes 2 lines at most. And the paint method will be invoked by its manager from the drawListRow method. Check back for more Blackberry tips on our blog in the future!


New Project Request