好吧,这篇博文我要改成原创,原创的内容是:让图标显示透明背景,而不是原文的白色背景!
下面的代码,可以让你的程序变化图标
Bitmap icon=Bitmap.getBitmapResource("icon/unread.gif");
net.rim.blackberry.api.homescreen.HomeScreen.updateIcon(icon,1);
但是这还不够酷,能在图标上面加数字呢?数字用来指示有几个待办, 或者是气温多少?
把上面的代码改良一下:
Bitmap icon=Bitmap.getBitmapResource("icon/unread.gif");
Bitmap icon1 = getUpdateIconBitmap(icon, count);
net.rim.blackberry.api.homescreen.HomeScreen.updateIcon(icon1,1);
private Bitmap getUpdateHomeScreenIcon(Bitmap bmp, int count)
{
if(count<=0) {return bmp;}
if(count>99) {count=99;}
int width = bmp.getWidth();
int height = bmp.getHeight();
int data[]=new int[width*height];
Bitmap iconBmp = new Bitmap(width, height);
iconBmp.setARGB(data, 0, width, 0,0,width,height);
Graphics g= Graphics.create(iconBmp);
XYRect rect = new XYRect(0, 0, width, height);
g.drawBitmap(rect, bmp, 0, 0);
g.setFont(g.getFont().derive(Font.BOLD, 20, Ui.UNITS_px, 0, Font.COLORED_OUTLINE_EFFECT));
String text = Integer.toString(count);
g.drawText(text, 0, 0);
return iconBmp;
}