views:

1294

answers:

1

How do we set the background and font colors in a RichTextField? I tried to override the paint() method in addition to what has been described here, but when I scroll down in, the background gets erased or reset to a white background

+2  A: 

In RIM 4.6 and greater you can use Background:

class ExRichTextField extends RichTextField {

 int mTextColor;

 public ExRichTextField(String text, int bgColor, int textColor) {
  super(text);
  mTextColor = textColor;
  Background background = BackgroundFactory
    .createSolidBackground(bgColor);
  setBackground(background);
 }

 protected void paint(Graphics graphics) {
  graphics.setColor(mTextColor);
  super.paint(graphics);
 }
}

For RIM 4.5 and lower use paint event to draw background youreself:

class ExRichTextField extends RichTextField {

 int mTextColor;
 int mBgColor;

 public ExRichTextField(String text, int bgColor, int textColor) {
  super(text);
  mTextColor = textColor;
  mBgColor = bgColor;
 }

 protected void paint(Graphics graphics) {
  graphics.clear();
  graphics.setColor(mBgColor);
  graphics.fillRect(0, 0, getWidth(), getHeight());
  graphics.setColor(mTextColor);
  super.paint(graphics);
 }
}
Max Gontar
Thanks, works like a breeze! However, when I add it to the VerticalFieldManager, i don't see the scrollbars, I have set the Manager's style to VERTICAL_SCROLL } VERTICAL_SCROLLBAR. Any reason why it does not appear?
Ram
Can't resolve this.. Seems like scrollbar not appears when preferred size of manager is set.
Max Gontar
One more problem that I encounter was when I add the ExRichTextField to the VerticalFieldManager after the BitmapField, the whole screen scrolls instead of the ExRichTextField alone scroll, which is the expected behaviour. Would adding two managers to the class resolve the problem?
Ram
Hi Ram! seems like no workaround to display standard scrollbar, so I just draw it custom. see update http://stackoverflow.com/questions/1426081/creating-custom-layouts-in-blackberry/1428106#1428106
Max Gontar