您的位置:首页 > 编程语言 > Java开发

在黑莓手机上通过Java程序更新应用的图标,并且图标上面带数字

2010-06-03 22:14 253 查看
下面的代码,可以让你的程序变化图标

 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 getUpdateIconBitmap(Bitmap bmp, int count) {
    int width = bmp.getWidth();
    int height = bmp.getHeight();
    Bitmap iconBmp = new Bitmap(width, height);
    Graphics g = new Graphics(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,
      Font.ANTIALIAS_STANDARD, Font.COLORED_OUTLINE_EFFECT));

    String text = Integer.toString(count);
    g.setColor(Color.RED);
    g.drawText(text, 0, 0);

    return iconBmp;
 }

                  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐