最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android界面 NotificationManager使用Bitmap做圖標(biāo)

 更新時(shí)間:2012年12月13日 18:01:03   作者:  
Android界面 NotificationManager使用Bitmap做圖標(biāo),如何實(shí)現(xiàn)呢,本文將介紹解決方法,需要的朋友可以參考下
今天看到EOE問答里面有這“[Android 界面]NotificationManager 如何使用Bitmap做圖標(biāo)”這樣一個(gè)問題,在論壇搜索也沒有好的案例

特寫一個(gè)簡單的demo供大家參考
今天發(fā)布的是NotificationManager 使用Bitmap做圖標(biāo)
關(guān)鍵code
復(fù)制代碼 代碼如下:

public void notification(int flag)
{
Notification notification = new Notification();
//設(shè)置statusbar顯示的icon
notification.icon = R.drawable.icon;
//設(shè)置statusbar顯示的文字信息
// myNoti.tickerText= new_msg ;
notification.flags = Notification.FLAG_AUTO_CANCEL;
//設(shè)置notification發(fā)生時(shí)同時(shí)發(fā)出默認(rèn)聲音
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
{
//此處是關(guān)鍵地方,可以從網(wǎng)絡(luò)或是sdcard上獲取圖片,轉(zhuǎn)成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, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
notification.contentIntent = contentIntent;
//顯示Notification
Random random = new Random(new Date().getTime());
mNotificationManager.notify(random.nextInt(1000000), notification);
}
//轉(zhuǎn)化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, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
drawable.draw(canvas);
return bitmap;
}

源碼下載:NotificationIcon.rar

相關(guān)文章

最新評論

卢龙县| 新津县| 易门县| 大渡口区| 清徐县| 巴林右旗| 南乐县| 郑州市| 通城县| 绵阳市| 新宾| 云阳县| 唐河县| 清水河县| 湘西| 赫章县| 上犹县| 桃园县| 巩义市| 冀州市| 修武县| 抚宁县| 东乡县| 伊宁市| 宜城市| 会宁县| 九龙县| 临西县| 绥芬河市| 汝城县| 玛纳斯县| 安吉县| 青神县| 九龙城区| 洪洞县| 聊城市| 江津市| 类乌齐县| 万载县| 休宁县| 福安市|