我刚刚接触黑莓,现在开发中遇到一个问题:制作了一个列表式的菜单,用的是ListField这个类做的,现在问题是:当前行被选中时显示的是系统默认颜色为蓝色,我想改变当前被选中的行的背景色并设置成渐变效果,希望有能人异士可以帮帮我。
------解决方案--------------------------------------------------------
重写paint代码,猜的啊。
------解决方案--------------------------------------------------------
graphic.drawfilledpath
------解决方案--------------------------------------------------------
重写OnDraw 肯定对的。。。
------解决方案--------------------------------------------------------
//设置当前被选中的行的背景颜色为蓝色
graphics.setBackgroundColor(Color.ORANGE);
渐变效果嘛,这个我就不知道了。
------解决方案--------------------------------------------------------
protected void drawFocus(Graphics g, boolean on) {
// 检索当前的重点区域。
getFocusRect(_tmpRect); // Retrieves this field's current focus region.
// 查看它师是否得到焦点
boolean oldDrawStyleFocus = g
.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS);
// 得到背景色
int oldBackgroundColour = g.getBackgroundColor();
// 使选中的区域的xy和位置和偏移的距离!
boolean notEmpty = g.pushContext(_tmpRect.x, _tmpRect.y,
_tmpRect.width, _tmpRect.height, 0, 0);
try {
if (notEmpty) {
if (on) {
// 使字体和背景显示一个颜色是,发生改变!
// g.setDrawingStyle(Graphics.DRAWSTYLE_FOCUS, true);
// 使选中的背景色
g.setBackgroundColor(_selectColor);
}
// 画完后清除画笔
g.clear();
//画笔
paint(g); // 修改了背景色后,调用HyperlinkButtonField.paint()来重新画,以显示背景色,下划线文字
}
} finally {
g.popContext();
g.setBackgroundColor(oldBackgroundColour);// 这里用临时变量来恢复Graphics原来的背景色
g.setDrawingStyle(Graphics.DRAWSTYLE_FOCUS, oldDrawStyleFocus);
}
}
------解决方案--------------------------------------------------------
照着上面做,重写LIstfield