【问题标题】:How to make notification icon in android如何在android中制作通知图标
【发布时间】:2012-07-16 01:43:45
【问题描述】:

我想在我的应用程序中创建一个通知图标,它显示我的应用程序中发生的任何新事件,就像您在 android 中找到的新消息或新邮件一样。你们能帮我提供一个链接或分享你自己的想法来实现这个..

【问题讨论】:

  • 这是一个关于如何制作图标本身的问题吗?或者如何在通知中包含图标?
  • 你可以这样做:Notification notification=new Notification(icon, text, when);其中图标是 int icon=R.drawable.ic_launcher;传递您想要保留在通知中的任何图标
  • 本教程将帮助您创建通知:Android notification tutorial
  • 我需要一个图标,我可以在其中传递一个值,该值将显示为没有通知或没有要查看的事件,类似于您在 facebook 中看到的
  • 试过什么?没有冒犯,但您的英语很差,也许如果您添加一些代码并说明您尝试过的内容,那么我们可以更轻松地为您提供帮助。

标签: android icons


【解决方案1】:

找到了一个很棒的通知教程http://www.tutorialspoint.com/android/android_notifications.htm 这有更多的细节,但对于一个简单的图标......

将通知图标复制到可绘制文件夹中

将以下变量添加到您的活动中

private NotificationManager mNotificationManager;
private int notificationID = 100;

添加以下方法

// Start the Notification Icon
protected void displayNotification() {
    Log.i("Start", "notification");

    /* Invoking the default notification service */
    NotificationCompat.Builder  mBuilder = new NotificationCompat.Builder(this);    
    mBuilder.setSmallIcon(R.drawable.fl_notification);
    mBuilder.setContentTitle("Flashlight");

    mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    /* notificationID allows you to update the notification later on. */
    mNotificationManager.notify(notificationID, mBuilder.build());

 }


// Stop the Notification Icon
 protected void cancelNotification() {
    Log.i("Cancel", "notification");
    mNotificationManager.cancel(notificationID);
 }

【讨论】:

    【解决方案2】:

    现在创建Notification 的首选方法是使用Notification.Builder 类。 Here 您可以找到文档和使用此类的示例。它有一个 setSmallIcon() 方法,这正是您所需要的。希望这会有所帮助。

    【讨论】:

      【解决方案3】:

      您可以使用 Toast。 Toast 通知是在窗口表面弹出的消息。 示例:

      Toast toast = Toast.makeText(context, text, duration);
      toast.show();
      

      更详细的可以看http://developer.android.com/guide/topics/ui/notifiers/index.html

      【讨论】:

      • Toast 和这个问题有什么关系?
      猜你喜欢
      • 2023-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-24
      • 1970-01-01
      • 1970-01-01
      • 2011-08-13
      • 1970-01-01
      相关资源
      最近更新 更多