Grey buttons when adding actions to notifications in Jelly Bean
Asked Answered
H

2

10

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);
Hispania answered 26/8, 2012 at 20:44 Comment(7)
have you tried with Notification.Builder instead of NotificationCompat.BuilderCountryside
yup, still there :-( Strangest problem I've had since Android 1.1...Hispania
It looks like the Holo.Light theme is being used. Could you try forcing the Holo.Dark theme, or at least inherit the Holo.Dark theme in your own theme? Also, you could check out Holo Everywhere so that it'll bleed onto the older versions of Android if you want. holoeverywhere.comInhabited
Or perhaps you're using the android-support.jar from API 15?Inhabited
I am using support lib v4 and used the Theme.Black and Theme.Holo (dark) but no change. Good thought though!Hispania
Try running this sample project and see what happens: github.com/commonsguy/cw-omnibus/tree/master/Notifications/… Themes should not be an issue AFAIK, since your theme won't affect the notification drawer.Chiseler
So this is happening to me as well. My guess is that this is due to having a target of version 8, which I believe tells the OS to do certain things for compatibility. Will try it on the sample project.Monteux
M
11

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.

Monteux answered 27/8, 2012 at 22:37 Comment(4)
I missed that you are targeting 16. That's definitely the case?Monteux
No that's not the case :-) I changed it but Eclipse has some refresh issues sometimes so it didn't get changed until I ran a clean. So now they are beautiful! Thanks a lot, though I cannot change the targetSDK in the near future so I'll have to wait with this feature then.Hispania
How can an apps API Level device which theme is being used in the notification bar? Shouldn't the notification bar be at it's own API level with the rest of the OS?Inhabited
You would think so... but clearly that isn't the case :( You can make custom views for your notifications, and notifications changed quite a bit between gingerbread and honeycomb, so I assume that's why they put in some compatibility junk for it.Monteux
M
0

Im having the same issue, using Android studio (0.8.11) with Gradle (0.13.0)

compileSdkVersion 20
buildToolsVersion "20.0"

defaultConfig {
        applicationId "x.xx.xxxxxx"
        minSdkVersion 10
        targetSdkVersion 20
        versionCode x
        versionName "x.xx"
    }

Solve it by adding uses-sdk to the Manifest

<uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="20" />

I know the Manifest value will be overridden by Gradle value. but that solve it.

Monday answered 24/9, 2014 at 14:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.