欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android界面 NotificationManager使用Bitmap做圖標

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

特寫一個簡單的demo供大家參考
今天發(fā)布的是NotificationManager 使用Bitmap做圖標
關(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ā)生時同時發(fā)出默認聲音
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)文章

  • Android編程實現(xiàn)自定義ImageView圓圖功能的方法

    Android編程實現(xiàn)自定義ImageView圓圖功能的方法

    這篇文章主要介紹了Android編程實現(xiàn)自定義ImageView圓圖功能的方法,結(jié)合實例形式分析了Android自定義ImageView及實現(xiàn)圓圖效果的具體步驟與相關(guān)操作技巧,需要的朋友可以參考下
    2017-08-08
  • Android給任何view添加全屏傾斜水印

    Android給任何view添加全屏傾斜水印

    本篇文章主要介紹了Android給任何view添加全屏傾斜水印,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-10-10
  • Android Intent傳遞對象的兩種方法(Serializable,Parcelable)詳細介紹

    Android Intent傳遞對象的兩種方法(Serializable,Parcelable)詳細介紹

    這篇文章主要介紹了Android Intent傳遞對象的兩種方法(Serializable,Parcelable)詳細介紹的相關(guān)資料,需要的朋友可以參考下
    2016-12-12
  • Tablayout簡單使用方法總結(jié)

    Tablayout簡單使用方法總結(jié)

    這篇文章主要為大家詳細總結(jié)了Tablayout的簡單使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • Android開發(fā)中聽筒無法播放音樂的解決方法

    Android開發(fā)中聽筒無法播放音樂的解決方法

    這篇文章主要介紹了Android開發(fā)中聽筒無法播放音樂的解決方法,涉及Android權(quán)限控制中的相關(guān)屬性設(shè)置技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2016-10-10
  • Android中通過反射實現(xiàn)圓角ImageView代碼實例

    Android中通過反射實現(xiàn)圓角ImageView代碼實例

    這篇文章主要介紹了Android中通過反射實現(xiàn)圓角ImageView代碼實例,本文直接給出核心實現(xiàn)代碼,需要的朋友可以參考下
    2015-04-04
  • Android如何獲取QQ與微信的聊天記錄并保存到數(shù)據(jù)庫詳解

    Android如何獲取QQ與微信的聊天記錄并保存到數(shù)據(jù)庫詳解

    這篇文章主要給大家介紹了關(guān)于Android如何獲取QQ與微信的聊天記錄并保存到數(shù)據(jù)庫的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧。
    2018-04-04
  • Flutter狀態(tài)管理Bloc之登錄示例

    Flutter狀態(tài)管理Bloc之登錄示例

    這篇文章主要為大家詳細介紹了Flutter狀態(tài)管理Bloc之登錄示例,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • android實現(xiàn)簡單左滑刪除控件

    android實現(xiàn)簡單左滑刪除控件

    這篇文章主要為大家詳細介紹了android實現(xiàn)一個簡單左滑刪除控件,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-08-08
  • 解決Android Studio 出現(xiàn)“Cannot resolve symbol” 的問題

    解決Android Studio 出現(xiàn)“Cannot resolve symbo

    今天在調(diào)試的時候,Android Studio報了一個莫名其妙的錯誤Cannot resolve symbol'R'讓人不知所措,因為這東西根本不歸我管啊,怎么會出現(xiàn) Cannot resolve symbol 這種錯誤呢?下面給大家分享Android Studio 出現(xiàn)“Cannot resolve symbol”解決方案,需要的朋友可以參考下
    2023-03-03

最新評論