2014-01-26 21 views
1

我想添加一個暫停按鈕,並在可能的情況下添加通知中的刪除按鈕。 像這樣:正常視圖中的Android通知按鈕

我怎樣才能做到這一點?

這是我的通知代碼:

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); 

回答

0

您將需要添加自定義視圖,它就像你如何顯示在主屏幕小部件的觀點:

看這個方法對通知生成器

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

通過它你的遠程視窗與您的佈局要的兩個按鈕。

小例子:

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