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

好吧,这篇博文我要改成原创,原创的内容是:让图标显示透明背景,而不是原文的白色背景!


下面的代码,可以让你的程序变化图标

 
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;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值