Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grey buttons when adding actions to notifications in Jelly Bean

I am adding two buttons to a notification in my app that is set to target API Level 8. The problem is that the two buttons appears as two large grey buttons, totally out of place with the rest of the notifications. I've tested it both on Nexus 7 and Galaxy Nexus.

enter image description here

All examples I've seen have the nice looking black buttons like the incoming call notification: http://www.androidng.com/wp-content/uploads/2012/07/android-jelly-bean-notifications.jpeg

I would guess this would be easy, but no such luck today. Does anyone know where I might have taken the wrong turn? Below is a snippet of my code which generates the notification with the latest support library.

NotificationManager nm = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);
android.support.v4.app.NotificationCompat.Builder builder = new android.support.v4.app.NotificationCompat.Builder(this);
    builder.setContentIntent(contentIntent)
                .setSmallIcon(R.drawable.ic_stat_radio)                
                .setContentTitle(message)
                .setTicker(message) 
                .setPriority(android.support.v4.app.NotificationCompat.PRIORITY_HIGH)
                .setWhen(System.currentTimeMillis())
                .setAutoCancel(false)                   
                .addAction(android.R.drawable.ic_btn_speak_now, "Play", contentIntent)
                .addAction(android.R.drawable.ic_dialog_map, "Stop", contentIntent)
                .setContentText(message);

    Notification n = builder.build();

    //nm.notify(0, n);
    startForeground(1, n);
like image 524
Christer Nordvik Avatar asked Aug 26 '12 20:08

Christer Nordvik


People also ask

How do I add an action button to my notifications?

Adding an action button: It is similar to setting the tap action by creating a pending intent only change is that we set it using addAction() to attach it to the notification. We can create intents for both activities or broadcast receivers as shown below: You can create your own BroadcastReciever.

Do push notifications have buttons?

What Are Push Notification Action Buttons? This is a case where the name is actually pretty self-explanatory: Push notification action buttons are literal buttons that can be added to the push notifications you send in order to allow recipients to take action on the messages they receive.

What is device notification?

A notification is a message that Android displays outside your app's UI to provide the user with reminders, communication from other people, or other timely information from your app. Users can tap the notification to open your app or take an action directly from the notification.

What is notification icon in Android?

App icon badges tell you when you have unread notifications. An app icon badge shows you the number of unread alerts and it's omnipresent on the app icon.


1 Answers

So this is happening because your targetSdk in your AndroidManifest.xml is < 11.

I believe the change in compatibility that happens when you target 11 is that the default theme because Holo. Since yours (and my) target is less than 11, it's resorting to some compatibility theme that it applies on these buttons even though it shouldn't. I assume that even though your app / activity is set to Holo, it doesn't actually apply to the notification since they are are in a different process.

That's just my guess. Using CommonsWare's notification demo and just modify the targetSdk shows this behavior.

like image 80
yincrash Avatar answered Oct 27 '22 13:10

yincrash