2010-11-05 141 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); 

     }