特写一个简单的demo供大家参考
今天发布的是notificationmanager 使用Bitmap做图标
关键code
复制代码 代码如下:
public voID notification(int flag)
{
Notification notification = new Notification();
//设置statusbar显示的icon
notification.icon = R.drawable.icon;
//设置statusbar显示的文字信息
// myNoti.tickerText= new_msg ;
notification.flags = Notification.FLAG_auto_CANCEL;
//设置notification发生时同时发出默认声音
notification.defaults = Notification.DEFAulT_SOUND;
RemoteVIEws contentVIEw = new RemoteVIEws(getPackagename(),R.layout.custom_notification);
Bitmap bitmap=null;
if(flag==0)
{
bitmap=drawabletoBitmap(this.getResources().getDrawable(R.drawable.icon));
}else
{
//此处是关键地方,可以从网络或是sdcard上获取图片,转成bitmap就可以
bitmap=drawabletoBitmap(this.getResources().getDrawable(R.drawable.alert_dialog_icon));
}
contentVIEw.setimageVIEwBitmap(R.ID.notification_icon,bitmap);
contentVIEw.setTextVIEwText(R.ID.app_name,"Custom notification");
notification.contentVIEw = contentVIEw;
Intent intent = new Intent(this,MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this,intent,
PendingIntent.FLAG_UPDATE_CURRENT);
notification.contentIntent = contentIntent;
//显示Notification
Random random = new Random(new Date().getTime());
mnotificationmanager.notify(random.nextInt(1000000),notification);
}
//转化drawabletoBitmap
public static Bitmap drawabletoBitmap(Drawable drawable)
{
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWIDth(),drawable.getIntrinsicHeight(),drawable.getopacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0,drawable.getIntrinsicWIDth(),drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
}
源码下载:NotificationIcon.rar 总结
以上是内存溢出为你收集整理的Android界面 NotificationManager使用Bitmap做图标全部内容,希望文章能够帮你解决Android界面 NotificationManager使用Bitmap做图标所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)