2010-11-05 79 views
9

Android開發新手。我想知道是否有可能以編程方式繪製圖標放入通知欄?如果我們希望圖標顯示某些類似電池電量的動態文本,該怎麼辦?Android通知圖標

如果有人有代碼示例,它會很好。謝謝。

+0

您是否找到解決方案? – 2011-09-06 08:39:11

+0

不幸的是沒有。我會認爲應該有一種方法來引用一個類作爲可繪製的資源,所以一個圖像可以通過編程繪製,但我不花很多時間或對Android非常瞭解...... :( – 2011-10-22 01:17:20

回答

1
+0

那不是我所知道的尋找。謝謝,但我知道如何發佈通知。我正在詢問如何使用通知圖標上的圖像。Notification.icon似乎只接受一個int作爲資源ID。 – 2010-11-05 01:48:41

+0

The狀態欄圖標不能,但擴展通知後出現的擴展文本是可能的 – xandy 2010-11-05 01:52:49

+0

呃,這看起來很糟糕,所以要在狀態欄的圖標頂部粘貼一些文本,你必須爲每個場景? – 2010-11-05 01:56:17

4

呼叫我們想要通知的功能。

public void notification(String name) { 

      final int id = 2; 
      String ns = Context.NOTIFICATION_SERVICE; 
      NotificationManager notificationManager = (NotificationManager) getSystemService(ns); 
      int icon = R.drawable.fbc; 
      CharSequence tickerText = "facebook"; 
      long when = System.currentTimeMillis(); 

      Notification checkin_notification = new Notification(icon, tickerText, 
        when); 
      Context context = getApplicationContext(); 
      CharSequence contentTitle = "You are name is"+ name; 
      CharSequence contentText = "Do You want to Check-in ?? "; 

       Intent notificationIntent = new Intent(context, LoginTab.class); 
       PendingIntent contentIntent = PendingIntent.getActivity(context, 0, 
         notificationIntent, 0); 
       checkin_notification.setLatestEventInfo(context, contentTitle, 
         contentText, contentIntent); 
       checkin_notification.flags = Notification.FLAG_AUTO_CANCEL; 
       notificationManager.notify(id, checkin_notification); 

     }