普通视图中的Android通知按钮

时间:2014-01-26 19:37:54

标签: android notifications

我想添加一个暂停按钮,如果可能的话,还会在通知中添加一个删除按钮。 像这样:

我该怎么做?

这是我的通知代码:

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

    context = getApplicationContext();
    builder = new NotificationCompat.Builder(context)
    .setContentTitle("Go!")
    .setContentText("Timer set to " + waitingtime/1000 + " seconds")
    .setTicker("Started!")
    .setWhen(System.currentTimeMillis())
    .setDefaults(Notification.DEFAULT_SOUND)
    .setAutoCancel(false)
    .setOngoing(true)
    .setSmallIcon(R.drawable.notlogosmall);

1 个答案:

答案 0 :(得分:0)

您需要添加自定义视图,就像您在主屏幕小部件上显示视图一样:

在Notification Builder上查看此方法

http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setContent(android.widget.RemoteViews)

使用布局中所需的两个按钮将其传递给RemoteView。

小例子:

    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.custom_notification);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
         .setSmallIcon(R.drawable.ic_launcher)
         .setContent(remoteViews);